With an XML Schema, is it possible to enforce a specific order of an element's attributes? If attributes are not in the specified order, them a validation error is generated.
No. In fact the XML Recommendation specifically says that the order of attributes in an element is not significant.
Edit: after letting that sit for a while, I thought it might be a bit hasty. After all you can use a schema to require all kinds of things which the XML Recommendation doesn't mention. So why not this one?
Here's why I think not. Since the Recommendation says that the order of attributes isn't significant, XML serializers can (and do) use this rule to output attributes in any order they see fit. Now suppose that a schema could override that and make the order significant. Then it would be necessary for the calling program to communicate that information to the serializer, perhaps by passing a reference to the schema to the serializer.
But I observe that XML serializers don't have that facility built into them. So that suggests to me that the committee who designed XML Schema wouldn't have allowed that feature to exist in Schema, because it would break all existing serializers.
Jimmy Clark
Ranch Hand
Joined: Apr 16, 2008
Posts: 2187
posted
0
Thanks. I thought so, but wanted to see if I was just unaware. For the application we are building, we need to enforce a specific order so that the flat files generated from the XML follow the defined format for each record.
We'll put a filter in place to extract the attibutes of the important elements and get them in the right order...(extra processing time.) Was just trying to see if this can be done via schema. Thanks again.