How to validate an xml with repeating child elements

Posted by gsk on Stack Overflow See other posts from Stack Overflow or by gsk
Published on 2010-04-07T07:27:06Z Indexed on 2010/04/07 7:33 UTC
Read the original article Hit count: 384

Filed under:

I have an xml document with three child elements repeating in any order. I had element in the xsd because of which the xml doesn't get validated. I can not use because the elements occur more than once.

Kindly help me on this.

Here is the xml

 <Trailer>      
        <TrailerField name="SegmentLabelOne" length="4" type="String">TSTS</TrailerField>
        <TrailerField name="SegmentLabelTwo" length="2" type="String">00</TrailerField>
       <CountItem length="10" type="Numeric">MT</CountItem> 
        <TrailerField name="SegmentLabelThree" length="2" type="String">01</TrailerField>
        <CountItem length="10" type="Numeric">MA</CountItem>
        <TrailerField name="SegmentLabelFour" length="2" type="String">02</TrailerField>
        <TrailerField name="FilerOne" length="65" type="String">                                                                 </TrailerField>
 </Trailer>

And here is the xsd

<xsd:complexType name="TrailerSegment">
<xsd:sequence>
            <xsd:element name="NameOfElement" minOccurs="0" maxOccurs="unbounded">
                <xsd:complexType>
                    <xsd:simpleContent>  
                        <xsd:extension base="xsd:string">  
                            <xsd:attribute name="name" type="xsd:string"></xsd:attribute>
                        </xsd:extension>
                    </xsd:simpleContent>
                </xsd:complexType>
            </xsd:element>
            <xsd:element name="CountItem" minOccurs="0" maxOccurs="unbounded">
                <xsd:complexType>
                    <xsd:simpleContent>  
                        <xsd:extension base="xsd:string">
                            <xsd:attribute name="length" type="xsd:string"></xsd:attribute>
                            <xsd:attribute name="type" type="xsd:string"></xsd:attribute>
                        </xsd:extension>
                    </xsd:simpleContent>
                </xsd:complexType>
            </xsd:element>
            <xsd:element name="TrailerField" minOccurs="0" maxOccurs="unbounded">
                <xsd:complexType>
                    <xsd:simpleContent>  
                        <xsd:extension base="xsd:string">  
                            <xsd:attribute name="name" type="xsd:string"></xsd:attribute>
                            <xsd:attribute name="length" type="xsd:string"></xsd:attribute>
                            <xsd:attribute name="type" type="xsd:string"></xsd:attribute>
                        </xsd:extension>
                    </xsd:simpleContent>
                </xsd:complexType>
            </xsd:element>
</xsd:sequence>
</xsd:complexType>

© Stack Overflow or respective owner

Related posts about Xml