[web-devel] Cannot control order of XML attributes

Yitzchak Gale gale at sefer.org
Sun Apr 3 22:17:11 CEST 2011


I wrote:
>>> After upgrading to xml-enumerator 0.2.1 and xml-types 0.2,
>>> I can no longer control the order of attributes in rendered XML.

John Millikin wrote:
> What sort of order do they need to be in?

I need them to be in semantic order, i.e., the order I specify.

I am building a very large and complex XML document
from scratch and rendering it using xml-enumerator, via
xml-types.

Some examples:

Some elements have attributes that specify the location
of an object in a large hierarchy. To make sense to a human,
the layers of the hierarchy must be listed in order.

Some elements have some attributes that specify location,
and other attributes that specify properties. Mixing
attributes between the two groups would make human
readers scratch their heads in confusion.

Etc.

> The only case I can think of where you'd need to store attribute
> ordering metadata in the attributes themselves is if you need them to
> be printed in exactly the order they were parsed.

They weren't parsed. They were built by my application.
And I need them to be in the semantic order that I specify,
so that they will make sense when read by humans.

That is actually a very common requirement -
you need it for any XML that will be read by humans
for any reason. E.g., for QA, for acceptance review, for
XML that will be edited by content writers, etc.

>>> Why not just use association lists? That seems like a perfect
>>> fit. Or just go back to the old API.

> I really don't want to go back to the old API. The 'Attribute' data
> type was annoying and unnecessary.

It was a bit unwieldy, but it worked.

Michael Snoyman wrote:
>> ...it's a little more difficult to code against the current
>> API than if we used an assoc list.

I agree.

>> I'm also not certain that we're gaining any performance
>> by using Map

> Some XML document formats use attributes extensively -- for these, the
> extra performance can matter. For example, if some element type
> supports 400 attributes, and a particular element of that type has
> 100, looking them up with an association list will be much slower than
> in a map.

True. On the other hand, in an XML document like the ones
I am working with - containing literally millions of elements each
containing at most a handful of attributes - using maps is likely
significantly *slower* than association lists. And I think the case
of a handful of attributes per element is far more common than
the case of hundreds.

Anyway, I definitely need control over attribute order, as allowed
by the spec.

Thanks,
Yitz



More information about the web-devel mailing list