我不知道为什么,但 dom4j 不加载 xmlns 属性,例如:
xmlns="http://webservices.example.com/servicesplatform/command/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
其他属性正常加载,但会被忽略。我使用所有元素的属性迭代器检查所有属性。
有一个例子,我如何阅读这个 xml:
SAXReader reader = new SAXReader();
Document document = reader.read(file);
return document;
我不知道我能尝试什么。 :(知道如何从 xml 文件中获取此属性吗?:(
编辑: 我像这样迭代它们
public void getAllAttributes(Element element) {
Iterator<Attribute> attributeterator = element.attributeIterator();
while (attributeterator.hasNext()) {
Attribute attribute = iteratorAttribute.next();
System.out.println(attribute.getQualifiedName() + " " + , attribute.getValue());
}
}
最佳答案
您可以通过以下方式获取默认命名空间
element.getNamespace()
所有其他命名空间都可以通过以下方式获取
element.additionalNamespaces()
关于java - dom4j 在读取时忽略 xmlns 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17580537/