On Tue, 3 Aug 2010, Greg Brown wrote:
in the DOM order has relevance. Attributes are stored as a list, not a
map. Pivot's org.apache.pivot.xml.Element class provides both keyed
and indexed access to attributes.
Huh? What language/implementation of the DOM are you referencing?
I'm looking at Java's org.w3c.dom.Node, in which an element's
attributes are represented by a org.w3c.dom.NamedNodeMap.
An element's child nodes are also accessible via Node#getChildNodes(),
which returns an ordered list of children.
True, but attributes are not children of elements and are not returned in
a call to getChildNodes().
Anyway, a list is a map. Or to put it another way, any collection can
be represented by a list simply by enumerating the elements of that
collection in some way. That does not imply that that collection has
some kind of innate or natural ordering.
It depends on the implementation of the map. Some have an implicit
order, while others do not. For example, the JDK supports a SortedMap
interface that imposes a strict ordering on key enumeration. A Pivot map
can be ordered by setting the comparator property.
There is nothing in the StAX spec that states that Attributes are
indexed by the order in which they are written.
Actually, there is. XMLStreamReader#getAttributeCount() returns the
number of attributes associated with the current element, and the
following methods return information about an attribute at a given
index:
getAttributeLocalName(int index)
getAttributeName(int index)
getAttributeNamespace(int index)
getAttributePrefix(int index)
getAttributeType(int index)
getAttributeValue(int index)
Thus, attributes in StAX have a specific ordering applied.
BXMLSerializer takes advantage of this feature to ensure that attributes
are processed in the correct order. Regardless, you can later access the
properties in an unordered way if the deserialized element is a
Dictionary or a bean that can be wrapped in a BeanAdapter.
Attributes in StAX have a specific ordering applied, but the spec says
nothing about what order that is. An implementation could order the
attributes in reverse to their appearance in the XML file and still be in
full compliance. An implementation need only provide some enumaration for
indexed access.
I'll ask you again to try to be a bit less aggressive and
arrogant-sounding with your posts. I have already explained why
attribute ordering is relevant in BXMLSerializer. I'm really not
interested in continuing to argue with you about it.
You are right---I came on pretty strong here and will tone it down. I'm
really not suggesting that attribute ordering is irrelevant to
BXMLSerializer. I'm just saying that XML doesn't provide attribute
ordering. It's just one of those limitations of XML as a serialization
language.
Cheers,
Michael