Reputation: 4648
i'm not the best at creating XSD schema as this is actually my first one, i would like to validate an xml that must look like this :
<?xml version="1.0"?>
<Data>
<FIELD name='toto'>
<META mono='false' dynamic='false'>
<COLUMN1>
<REFTABLE>table</REFTABLE>
<REFCOLUMN>key_column</REFCOLUMN>
<REFLABELCOLUMN>test_column</REFLABELCOLUMN>
</COLUMN1>
<COLUMN2>
<REFTABLE>table</REFTABLE>
<REFCOLUMN>key_column</REFCOLUMN>
<REFLABELCOLUMN>test_column</REFLABELCOLUMN>
</COLUMN2>
</META>
<VALUEs>
<VALUE>...</VALUE>
</VALUEs>
</FIELD>
My problem is that into the META block the tags "COLUMN1","COLUMN2" are always different, it may become COLUMNxxx. For now my schema is :
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="Data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="FIELD" type="Field" />
</xsd:sequence>
<xsd:attribute name="id" type="xsd:int" use="required" />
</xsd:complexType>
</xsd:element>
<xsd:complexType name="dataSourceDef">
<xsd:sequence>
<xsd:element name="DSD_REFTABLE" type="xsd:string" />
<xsd:element name="DSD_REFCOLUMN" type="xsd:string" />
<xsd:element name="DSD_REFLABELCOLUMN" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="MetaTag">
<xsd:sequence>
<xsd:any processContents="lax" />
</xsd:sequence>
<xsd:attribute name="mono" type="xsd:string" use="required" />
<xsd:attribute name="dynamic" type="xsd:string" use="required"/>
</xsd:complexType>
<xsd:complexType name="Field">
<xsd:sequence>
<xsd:element name="META" type="MetaTag" minOccurs="1" />
<xsd:element name="VALUEs">
<xsd:complexType>
<xsd:sequence>
<xsd:any processContents="lax" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required"/>
</xsd:complexType>
</xsd:schema>
And i just can't get it to work, i don't know how to handle the fact that a precise level of my nodes isn't clear, and the rest is.
Would you help me please ?
Upvotes: 2
Views: 4872
Reputation: 7279
I think the problem is that, in your schema, <xsd:any/>
will only accept one single element. You need to tell that there can be any number of children with the attributes minOccurs and maxOccurs:
<xsd:sequence>
<xsd:any processContents="lax" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
Upvotes: 1
Reputation: 161783
You can't have a document like this and validate against an XML Schema. Use
<COLUMN name="Column1"/>
instead.
Upvotes: 3