获取以下 XML 元素的属性详细信息
<catalog e="1" b="2" a="0">
我使用NamedNodeMap
要获取属性,请将属性排序为
a = 0, b = 2, e = 1
如何按原样打印它?
最佳答案
属性排序不是 DOM Level 3 的功能其中the Java type implements 。请参阅W3C documentation for NamedNodeMap :
NamedNodeMap
s are not maintained in any particular order. Objects contained in an object implementingNamedNodeMap
may also be accessed by an ordinal index, but this is simply to allow convenient enumeration of the contents of aNamedNodeMap
, and does not imply that the DOM specifies an order to these Nodes.
如果您需要这个,标准 DOM 并不是您想要的。
关于java - 对象在 NamedNodeMap 中排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17258150/