- From: Costello, Roger L. <costello@mitre.org>
- Date: Thu, 20 Sep 2012 13:33:58 +0000
- To: "xmlschema-dev@w3.org" <xmlschema-dev@w3.org>
Hello Folks, I have stumbled upon a fascinating problem (I didn't recognize fully the problem until Michael Kay explained it to me). Consider the following XML document. There are two <Attitude> elements; they have a mandatory "reference" attribute and an optional "units" attribute: <Test> <Altitude reference="MSL" units="feet" /> <Altitude reference="AGL"/> </Test> I want an XPath that does this test: For the Attitude that has @units="feet", does it have @reference="MSL"? Here is the XPath: /Test/Altitude[@units eq 'feet']/@reference eq 'MSL' That XPath works fine. Notice that it uses "eq". Recall that "eq" can only be used when there is exactly one occurrence. This expression: /Test/Altitude[@units eq 'feet'] yields only one Altitude element, so it is okay to then test: @reference eq 'MSL' Now suppose that in the XML Schema @units is declared to be fixed: <xs:attribute name="units" type="xs:string" fixed="feet" /> Although the XML instance document doesn't show @units on the second Altitude element it is there. So, given the XML Schema, does this expression still yield only one Altitude element: /Test/Altitude[@units eq 'feet'] Suppose that that expression is used in an XSD 1.1 assert element: <xs:element name="Test"> <xs:complexType> <xs:sequence> <xs:element name="Altitude" maxOccurs="unbounded"> <xs:complexType> <xs:attribute name="units" type="xs:string" fixed="feet" /> <xs:attribute name="reference" use="required"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:enumeration value="MSL" /> <xs:enumeration value="AGL" /> </xs:restriction> </xs:simpleType> </xs:attribute> </xs:complexType> </xs:element> </xs:sequence> <xs:assert test="Altitude[@units eq 'feet']/@reference eq 'MSL'" /> </xs:complexType> </xs:element> Is this XML instance document valid: <Test> <Altitude reference="MSL" units="feet" /> <Altitude reference="AGL"/> </Test> How many Attitude elements are there with @units eq "feet"? One or two? /Roger
Received on Thursday, 20 September 2012 13:34:30 UTC