Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Having trouble coming up with schema (xsd) for this xml document... 1

Status
Not open for further replies.

ptxyz

Programmer
Oct 22, 2007
4
US

Hi All,

I have the following xml document (see below) and am trying to come up with the xsd schema for it.

XML document:
<root>
<scenario>
<name>TEST1</name>
<params>
<first_name>Mike</first_name>
<last_name>Smith</last_name>
<job>Tester</job>
</params>
</scenario>
<scenario>
<name>TEST2</name>
<params>
<item>Test item</item>
<date>03/10/2010</item>
</params>
</scenario>
<scenario>
<name>TEST3</name>
</scenario>
</root>

Partial XSD schema (as far as I can get):
<xs:element name="IAUTO">
<xs:complexType>
<xs:sequence>
<xs:element name="SCENARIO" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="NAME" type="xs:string"/>
???<xs:element name="PARAMS">
???</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>

The problem I'm having is with scenario.params - the structure of params is different for every scenario.

Say there are 100 or so different scenarios and each scenario can have 0-20 parameters...
My goal here is to do validation, to make sure TEST1 scenario (for example) has correct params in the xml file. Also, xml document structure is not set in stone...

Thanks for any help / suggestions.
-Pavel
 
[1] Cases are sensitive. IAUTO is not root. SCENARIO is not scenario.
[2] It is not within the scope of WXSL (xsd) to impose child element structure according to a sibling's text child element. So if you mean schema by WXSL, you're out of luck.
[3] Better to make your own validation script expliciting the business logic or alternative schema(s) than WXSL.
[4] If you want to be done within WXSL leaving "params" element full liberty as to its child element structure, you can use xs:any to construct its complexType, as similar to what shown in a recent thread.
Just impose minOccurs="0" to allow even empty params.
 
Thanks for that info tsuji.

Regarding your uppercase note - my bad, that's just my example, it's actually all lowercase. Got myself confused while cut-n-pasting!

Thanks again and best regards.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top