Reputation: 249
I dont know why but dom4j is not load xmlns attributes such as:
xmlns="http://webservices.example.com/servicesplatform/command/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
Other attributes loads normally but that are just ignored. I check all attributes using attribute Iterator for all elements.
There is example how i read this xml:
SAXReader reader = new SAXReader();
Document document = reader.read(file);
return document;
I dont have idea what can i even try. :( Any idea how can I get this attributes from xml file? :(
EDIT: I am iterate through them like that
public void getAllAttributes(Element element) {
Iterator<Attribute> attributeterator = element.attributeIterator();
while (attributeterator.hasNext()) {
Attribute attribute = iteratorAttribute.next();
System.out.println(attribute.getQualifiedName() + " " + , attribute.getValue());
}
}
Upvotes: 1
Views: 1197
Reputation: 39363
I'm using dom4j 2.1.0, and the following code worked to get the default namespace:
document.getRootElement().getNamespaceURI()
It returns: http://webservices.example.com/servicesplatform/command/1.0.0
And you can get all the namespaces objects with:
document.getRootElement().additionalNamespaces()
Upvotes: 1
Reputation: 4041
You can get the default namespace by
element.getNamespace()
All the other namespaces can be obtained with
element.additionalNamespaces()
Upvotes: 0
Reputation: 4239
xmlns
attributes are Namespace's
. To read them using a Dom4j
, you can use any of the below two methods based on your needs:
Namespace.get(String prefix, String uri)
Upvotes: -1