1

To get attributes detail for following XML element

<catalog e="1" b="2" a="0">

I use NamedNodeMap to get attribute, It is sorting the attributes as

a = 0, b = 2, e = 1

How can I print it as it is?

2FaceMan
  • 443
  • 2
  • 18
  • 34

1 Answers1

1

Attribute ordering is not a feature of DOM Level 3 which the Java type implements. See the W3C documentation for NamedNodeMap:

NamedNodeMaps are not maintained in any particular order. Objects contained in an object implementing NamedNodeMap may also be accessed by an ordinal index, but this is simply to allow convenient enumeration of the contents of a NamedNodeMap, and does not imply that the DOM specifies an order to these Nodes.

If you require this, the standard DOM is not what you are looking for.

McDowell
  • 107,573
  • 31
  • 204
  • 267