W3C home > Mailing lists > Public > www-dom@w3.org > July to September 2001

Re: Order of attributes

From: Ray Whitmer <rayw@netscape.com>
Date: Wed, 18 Jul 2001 16:37:49 -0700
Message-ID: <3B561DCD.2000505@netscape.com>
To: Query Query <query4u@rediffmail.com>
CC: "www-dom@w3.org." <www-dom@w3.org>
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
rayw@netscape.com
Received on Wednesday, 18 July 2001 19:33:00 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Friday, 22 June 2012 06:13:49 GMT