Re: order of attributes

Hi Jean-Francois,

> Using a xml schema, how is it possible to impose the order of the
> attributes on a element in a xml instance? eg : on the element
> 'elem1' I want the attributes to appear in the order : first 'att1'
> then 'att2' and finally 'att3'.

The XML Rec says that the order in which attributes appear in a start
tag is insignificant. XML parsers are free to report the order of
attributes in any way that they like -- for example, they might report
them in alphabetical order if that makes the parser more efficient.

All the schema languages I know of, including XML Schema, work based
on the information that they can get from an XML parser. Since that
set of information doesn't include information about how the
attributes were originally ordered, no schema language gives you the
ability to check the order in which the attributes were specified.

So if this is really an important constraint in your documents, you
need to write a validator (in Perl or some other text-processing
language) that views the documents as streams of characters rather
than with the logical view that XML parsers provide. Most probably,
though, you should be using elements instead of attributes if the
order in which the information appears actually matters.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/

Received on Thursday, 17 July 2003 06:33:42 UTC