[
Lists Home |
Date Index |
Thread Index
]
Jim Acona wrote:
> Presumably a different rule applies for attributes, whose order cannot
> be constrained in any schema language I'm aware of, but should also
> never be significant.
RELAX NG, btw, handles attributes in an interesting way. You can apply
occurrence constraints uniformly to attributes just as you would elements;
nevertheless, a compliant RELAX NG processor will not permit duplicate
attributes in an instance or trouble itself over the order of attributes,
just as it should. An example follows to make it clear how this works.
Mike, RELAX NG devotee
===========example==================
C:\XML\Rng\Examples>cat atts.rng
<element name="date" xmlns="http://relaxng.org/ns/structure/1.0">
<attribute name="year"/>
<optional>
<attribute name="month"/>
</optional>
<zeroOrMore>
<attribute name="day"/>
</zeroOrMore>
<oneOrMore>
<attribute name="utc"/>
</oneOrMore>
</element>
C:\XML\Rng\Examples>grep date atts_?.xml
atts_1.xml:<date year="2003" month="January" day="21" utc="-08:00"/>
atts_2.xml:<date year="2003" month="January" day="20" day="21"
utc="-08:00"/>
atts_3.xml:<date year="2003" month="January" day="21" utc="-08:00"
utc="-08:00"/>
atts_4.xml:<date year="2003" month="January" utc="-08:00"/>
atts_5.xml:<date year="2003" month="January" day="21"/>
C:\XML\Rng\Examples>java -jar c:\lib\jing.jar atts.rng atts_1.xml
C:\XML\Rng\Examples>java -jar c:\lib\jing.jar atts.rng atts_2.xml
Fatal error at URL "file:/C:/XML/Rng/Examples/atts_2.xml", line number 1:
Attribute "day" already
appeared in this tag.
C:\XML\Rng\Examples>java -jar c:\lib\jing.jar atts.rng atts_3.xml
Fatal error at URL "file:/C:/XML/Rng/Examples/atts_3.xml", line number 1:
Attribute "utc" already
appeared in this tag.
C:\XML\Rng\Examples>java -jar c:\lib\jing.jar atts.rng atts_4.xml
C:\XML\Rng\Examples>java -jar c:\lib\jing.jar atts.rng atts_5.xml
Error at URL "file:/C:/XML/Rng/Examples/atts_5.xml", line number 1:
unfinished element
C:\XML\Rng\Examples>
|