XSD validation on recursive XML elements [modified]
-
Hi, I want to create a XSD schema to use for validating XML files like the following: top> top> top> top> /top> link> link> mid> mid> /top> top> bottom> /top> /top> A "top" element can contain any number of "top" elements or any number of "link" elements or any number of "mid" elements. A "top" element can contain only one "bottom" element and no other element if it contains a "bottom" element. A "link" or "mid" or "bottom" element cannot contain any elements. Any advice, please help? -- modified at 2:51 Wednesday 2nd May, 2007
-
Hi, I want to create a XSD schema to use for validating XML files like the following: top> top> top> top> /top> link> link> mid> mid> /top> top> bottom> /top> /top> A "top" element can contain any number of "top" elements or any number of "link" elements or any number of "mid" elements. A "top" element can contain only one "bottom" element and no other element if it contains a "bottom" element. A "link" or "mid" or "bottom" element cannot contain any elements. Any advice, please help? -- modified at 2:51 Wednesday 2nd May, 2007
Not tested, but should be at least a good starting point:
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema targetNamespace="http://tempuri.org/XMLSchema.xsd"
elementFormDefault="qualified"
xmlns="http://tempuri.org/XMLSchema.xsd"
xmlns:mstns="http://tempuri.org/XMLSchema.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="link">
xs:complexType</xs:complexType>
</xs:element><xs:element name="mid"> <xs:complexType></xs:complexType> </xs:element> <xs:element name="bottom"> <xs:complexType></xs:complexType> </xs:element> <xs:element name="top"> <xs:complexType> <xs:choice> <xs:sequence> <xs:element ref="mstns:bottom"></xs:element> </xs:sequence> <xs:sequence> <xs:choice minOccurs="0" maxOccurs="unbounded"> <xs:element ref="mstns:top"></xs:element> <xs:element ref="mstns:link"></xs:element> <xs:element ref="mstns:mid"></xs:element> </xs:choice> </xs:sequence> </xs:choice> </xs:complexType> </xs:element>
</xs:sche
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook
-
Hi, I want to create a XSD schema to use for validating XML files like the following: top> top> top> top> /top> link> link> mid> mid> /top> top> bottom> /top> /top> A "top" element can contain any number of "top" elements or any number of "link" elements or any number of "mid" elements. A "top" element can contain only one "bottom" element and no other element if it contains a "bottom" element. A "link" or "mid" or "bottom" element cannot contain any elements. Any advice, please help? -- modified at 2:51 Wednesday 2nd May, 2007
Or even simpler...
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xs:complexType name="top">
xs:sequence
<xs:element name="top" type="xs:string" minOccurs="0" maxOccurs="unbounded" />
<xs:element name="link" type="xs:string" minOccurs="0" maxOccurs="unbounded" />
<xs:element name="mid" type="xs:string" minOccurs="0" maxOccurs="unbounded" />
<xs:element name="bottom" type="xs:string" minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType><xs:element name="top" type="top" />
</xs:schema>
Try code model generation tools at BoneSoft.com.
-
Or even simpler...
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xs:complexType name="top">
xs:sequence
<xs:element name="top" type="xs:string" minOccurs="0" maxOccurs="unbounded" />
<xs:element name="link" type="xs:string" minOccurs="0" maxOccurs="unbounded" />
<xs:element name="mid" type="xs:string" minOccurs="0" maxOccurs="unbounded" />
<xs:element name="bottom" type="xs:string" minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType><xs:element name="top" type="top" />
</xs:schema>
Try code model generation tools at BoneSoft.com.
This doesn't cover the requirements that a "top" element can contain only one "bottom" element and no other element if it contains a "bottom" element.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook
-
This doesn't cover the requirements that a "top" element can contain only one "bottom" element and no other element if it contains a "bottom" element.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook
True, didn't realize that was a requirement. I guess choice is the only valid approach.
Try code model generation tools at BoneSoft.com.