Click here to Skip to main content
15,843,144 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to create a recursive XSD schema that validates a tree structure of an XML document.

Sample XML:

XML
<?xml version="1.0" encoding="UTF-8"?>
<MooNElements>
  <MooNElement>
    <MooNParameters>
      <MooNParameter/>
      <MooNParameter/>
    </MooNParameters>
    <MooNElement>
      <MooNParameters>
        <MooNParameter/>
        <MooNParameter/>
      </MooNParameters>
    </MooNElement>
    <MooNElement>
      <MooNParameters>
        <MooNParameter/>
        <MooNParameter/>
      </MooNParameters>
    </MooNElement>
  </MooNElement>
  <MooNElement>
    <MooNParameters>
      <MooNParameter/>
      <MooNParameter/>
      <MooNParameter/>
    </MooNParameters>
    <MooNElement>
      <MooNParameters>
        <MooNParameter/>
        <MooNParameter/>
      </MooNParameters>
    </MooNElement>
  </MooNElement>
  <MooNElement>
    <MooNParameters>
      <MooNParameter/>
      <MooNParameter/>
      <MooNParameter/>
    </MooNParameters>
  </MooNElement>
  <MooNElement>
    <MooNElement>
      <MooNParameters>
        <MooNParameter/>
        <MooNParameter/>
      </MooNParameters>
      <MooNElement>
        <MooNParameters>
          <MooNParameter/>
        </MooNParameters>
        <MooNElement>
          <MooNParameters>
            <MooNParameter/>
          </MooNParameters>
        </MooNElement>
      </MooNElement>
    </MooNElement>
  </MooNElement>
</MooNElements>


I had created the following XSD using VS 2010

XSD:

XML
<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="MooNElements">
    <xs:complexType>
      <xs:sequence>
        <xs:element maxOccurs="unbounded" name="MooNElement">
          <xs:complexType>
            <xs:sequence>
              <xs:element minOccurs="0" name="MooNParameters">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element maxOccurs="unbounded" name="MooNParameter" />
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
              <xs:element minOccurs="0" maxOccurs="unbounded" name="MooNElement">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element name="MooNParameters">
                      <xs:complexType>
                        <xs:sequence>
                          <xs:element maxOccurs="unbounded" name="MooNParameter" />
                        </xs:sequence>
                      </xs:complexType>
                    </xs:element>
                    <xs:element minOccurs="0" name="MooNElement">
                      <xs:complexType>
                        <xs:sequence>
                          <xs:element name="MooNParameters">
                            <xs:complexType>
                              <xs:sequence>
                                <xs:element name="MooNParameter" />
                              </xs:sequence>
                            </xs:complexType>
                          </xs:element>
                          <xs:element name="MooNElement">
                            <xs:complexType>
                              <xs:sequence>
                                <xs:element name="MooNParameters">
                                  <xs:complexType>
                                    <xs:sequence>
                                      <xs:element name="MooNParameter" />
                                    </xs:sequence>
                                  </xs:complexType>
                                </xs:element>
                              </xs:sequence>
                            </xs:complexType>
                          </xs:element>
                        </xs:sequence>
                      </xs:complexType>
                    </xs:element>
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>


How to simplify this inorder to validate the recursive nodes?

Thanks,

Sudheendra
Posted
Updated 29-Oct-14 2:22am
v3

1 solution

 
Share this answer
 
v2
Comments
Manoor Hebbar 29-Oct-14 7:14am    
I had generated the XSD (pasted below), but I would like to simply the XSD so that it can handle the requirement of recursive nodes
Maciej Los 29-Oct-14 9:59am    
Do not post code in comment. Use "Improve question" widget instead.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900