XML Schema question

This is a discussion on XML Schema question within the Tech Board forums, part of the Community Boards category; Let's say I have an XML document in the following format: Code: <?xml version="1.0" encoding="utf-8"?> <Document> <Object> <Child1> <SomeData></SomeData> </Child1> ...

  1. #1
    Registered User
    Join Date
    Oct 2006
    Posts
    2,502

    XML Schema question

    Let's say I have an XML document in the following format:

    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <Document>
      <Object>
        <Child1>
          <SomeData></SomeData>
        </Child1>
        <Child2>
          <SomeData></SomeData>
        </Child2>
        <Child3>
          <SomeData></SomeData>
        </Child3>
      </Object>
      <Object>
        <Child1>
          <SomeData></SomeData>
        </Child1>
      </Object>
    </Document>
    The XML schema for this file looks like this:

    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
      <xs:element name="Document">
        <xs:complexType>
          <xs:sequence>
            <xs:element maxOccurs="unbounded" name="Object">
              <xs:complexType>
                <xs:sequence>
                  <xs:element name="Child1">
                    <xs:complexType>
                      <xs:sequence>
                        <xs:element name="SomeData" />
                      </xs:sequence>
                    </xs:complexType>
                  </xs:element>
                  <xs:element minOccurs="0" name="Child2">
                    <xs:complexType>
                      <xs:sequence>
                        <xs:element name="SomeData" />
                      </xs:sequence>
                    </xs:complexType>
                  </xs:element>
                  <xs:element minOccurs="0" name="Child3">
                    <xs:complexType>
                      <xs:sequence>
                        <xs:element name="SomeData" />
                      </xs:sequence>
                    </xs:complexType>
                  </xs:element>
                </xs:sequence>
              </xs:complexType>
            </xs:element>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
    </xs:schema>
    is there a way to modify the XML schema file to recognize the individual <Child*> elements, but treat them as an array of <Child> elements (minOccurs="1" maxOccurs="unbounded") in code (C#) generated from the schema?

  2. #2
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    Doesn't xsd do this for you? If I remember correctly if your schema is correct xsd will create arrays for you. However there is a bug in xsd that causes multiple definitions to occur.

  3. #3
    Registered User
    Join Date
    Oct 2006
    Posts
    2,502
    the problem is with the fact that the elements are Child1, Child2, Child3, etc. xsd just sees them as independent elements, and doesn't know to put them into an array.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 03-23-2011, 09:00 AM
  2. What's the best way to parse XML Schema with C# Language.
    By userpingz in forum C# Programming
    Replies: 2
    Last Post: 11-13-2009, 06:25 AM
  3. class schema implementation doubt
    By newbie007 in forum C++ Programming
    Replies: 1
    Last Post: 06-15-2008, 04:42 PM
  4. Newbish Question file reading question....
    By kas2002 in forum C Programming
    Replies: 23
    Last Post: 05-17-2007, 12:06 PM
  5. Anyone good at XML Schema?
    By Waldo2k2 in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 05-30-2002, 10:05 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21