Problem designing xsd schema - because of a variable element name

Posted by ssaboum on Stack Overflow See other posts from Stack Overflow or by ssaboum
Published on 2010-03-19T12:48:28Z Indexed on 2010/03/19 12:51 UTC
Read the original article Hit count: 307

Filed under:
|
|

Hi everyone, 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 ?

thx

© Stack Overflow or respective owner

Related posts about Xml

Related posts about xml-schema