C
Clarence
Hi, here is an XML schema excerpt for an employees details.
<xs:element name="ADDRESS">
<xs:complexType>
<xs:sequence>
<xs:element name="ADDRESSLINE" type="xs:string" maxOccurs="6"/>
<xs:element name="HOUSENUMBER" type="xs:int" minOccurs="1"/>
<xs:element name="POSTCODE" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
What I want is to write an XML schema to validate my XML against and
guarantee that my XML has an <ADDRESS> somewhere in it. Here is an example
of a schema I have written and that works.
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="EMPLOYEE">
<xs:complexType>
<xs:sequence>
<--STUFF FROM ADDRESS COPIED ABOVE -->
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
This schema could be used to validate the following XML
<EMPLOYEE>
<ADDRESS>
<ADDRESSLINE>Downing Street</ADDRESSLINE>
<ADDRESSLINE>London</ADDRESSLINE>
<HOUSENUMBER>10</HOUSENUMBER>
<POSTCODE>SW1A 2AA</POSTCODE>
</ADDRESS>
</EMPLOYEE>
Any although it has taken a while to get this far, it isn't what I really
want. What I want is a schema to confirm there is an ADDRESS portion in the
XML, somewhere. For example I want the following XML to be schema valid
using the same XML schema too.
<EMPLOYEE>
<UK>
<ENGLAND>
<ADDRESS>
<ADDRESSLINE>Downing Street</ADDRESSLINE>
<ADDRESSLINE>London</ADDRESSLINE>
<HOUSENUMBER>10</HOUSENUMBER>
<POSTCODE>SW1A 2AA</POSTCODE>
</ADDRESS>
</ENGLAND>
</UK>
<EMPLOYEE>
And also the following
<EMPLOYEE>
<LEVEL1>
<LEVEL2>
<LEVEL3>
<ADDRESS>
<ADDRESSLINE>somewhere</ADDRESSLINE>
<ADDRESSLINE>somwhere</ADDRESSLINE>
<HOUSENUMBER/>
<POSTCODE>something</POSTCODE>
</ADDRESS>
</LEVEL3>
</LEVEL2>
</LEVEL1>
<EMPLOYEE>
The employee address details could be anywhere in the XML, not just the
examples I have given above. I want my XML schema to confirm that the XML
has an <ADDRESS> node SOMEWHERE in the XML. Does anyone have an idea how
this can be done? According to "XML in a nutshell", I think I should be
looking at xs:any but unfortunately don't (currently) have the skills to put
it all together.
I am also thinking that there might be an XPATH expression like
..//ADDRESS[ADDRESSLINE and HOUSENUMBER and POSTCODE]
somewhere in my XML schema but again I am lacking the required knowledge of
where to put it in.
Any help much appreciated.
Thank you
Clarence
<xs:element name="ADDRESS">
<xs:complexType>
<xs:sequence>
<xs:element name="ADDRESSLINE" type="xs:string" maxOccurs="6"/>
<xs:element name="HOUSENUMBER" type="xs:int" minOccurs="1"/>
<xs:element name="POSTCODE" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
What I want is to write an XML schema to validate my XML against and
guarantee that my XML has an <ADDRESS> somewhere in it. Here is an example
of a schema I have written and that works.
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="EMPLOYEE">
<xs:complexType>
<xs:sequence>
<--STUFF FROM ADDRESS COPIED ABOVE -->
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
This schema could be used to validate the following XML
<EMPLOYEE>
<ADDRESS>
<ADDRESSLINE>Downing Street</ADDRESSLINE>
<ADDRESSLINE>London</ADDRESSLINE>
<HOUSENUMBER>10</HOUSENUMBER>
<POSTCODE>SW1A 2AA</POSTCODE>
</ADDRESS>
</EMPLOYEE>
Any although it has taken a while to get this far, it isn't what I really
want. What I want is a schema to confirm there is an ADDRESS portion in the
XML, somewhere. For example I want the following XML to be schema valid
using the same XML schema too.
<EMPLOYEE>
<UK>
<ENGLAND>
<ADDRESS>
<ADDRESSLINE>Downing Street</ADDRESSLINE>
<ADDRESSLINE>London</ADDRESSLINE>
<HOUSENUMBER>10</HOUSENUMBER>
<POSTCODE>SW1A 2AA</POSTCODE>
</ADDRESS>
</ENGLAND>
</UK>
<EMPLOYEE>
And also the following
<EMPLOYEE>
<LEVEL1>
<LEVEL2>
<LEVEL3>
<ADDRESS>
<ADDRESSLINE>somewhere</ADDRESSLINE>
<ADDRESSLINE>somwhere</ADDRESSLINE>
<HOUSENUMBER/>
<POSTCODE>something</POSTCODE>
</ADDRESS>
</LEVEL3>
</LEVEL2>
</LEVEL1>
<EMPLOYEE>
The employee address details could be anywhere in the XML, not just the
examples I have given above. I want my XML schema to confirm that the XML
has an <ADDRESS> node SOMEWHERE in the XML. Does anyone have an idea how
this can be done? According to "XML in a nutshell", I think I should be
looking at xs:any but unfortunately don't (currently) have the skills to put
it all together.
I am also thinking that there might be an XPATH expression like
..//ADDRESS[ADDRESSLINE and HOUSENUMBER and POSTCODE]
somewhere in my XML schema but again I am lacking the required knowledge of
where to put it in.
Any help much appreciated.
Thank you
Clarence