Re: Order of attributes

Query Query wrote:

>Does W3 specification for DOM provide any explicit details on the order of attributes in an XML. Is there a way to know (after having parsed the XML) the order of attributes otherwise. 
Attributes are unordered within an element, I believe, according to XML 
and the infoset.  The order as well as any whitespace between attribute 
names and values is considered insignificant.  A parser may conspire 
with a DOM implementation to preserve it, but that is not something that 
DOM specifies how to do.

While there is some implemented order in which attributes of an element 
are returned if the attributes NamedNodeMap is accessed using the 
item(index) method, this order is specifically not significant or 
guaranteed to match the original document order.  In DOM implementations 
I have produced personally, attributes are returned alphabetically by 
attribute name -- it makes it easier to do a binary search for a 
specific attribute by name.  I do not doubt that some implementations 
may return them in the order in which they occurred in the document, but 
it is contrary to the DOM specification to rely on them being accessed 
in the order of appearance in the document, and you will find DOM 
implementations which will not return them in that order.

Ray Whitmer

Received on Wednesday, 18 July 2001 19:33:00 UTC