Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XSD Design - Element with same name, but different sub elements 1

Status
Not open for further replies.

rbutterwood

Programmer
Dec 7, 2005
3
US
Hi,

I want to have the following XML instance file:

<ResponseBatch>
<Response>
<ResponseName>Codes</ResponseName>
<CodeName>blah</CodeName>
</Response>
<Response>
<ResponseName>Items</ResponseName>
<ItemName>blah</ItemName>
</Response>
</ResponseBatch>

When I built the XSD it complained that I had a duplicate element name.

Can someone please help with the XSD design?
 
This schema works for the xml you posted.
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema"[/URL] elementFormDefault="qualified" attributeFormDefault="unqualified">
  <xs:element name="ENTER_NAME_OF_ROOT_ELEMENT_HERE">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="ResponseBatch">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="Response" maxOccurs="unbounded">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element name="ResponseName"/>
                    <xs:choice>
                      <xs:element name="CodeName"/>
                      <xs:element name="ItemName"/>
                    </xs:choice>
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

____________________________________________________________________
Donate to Katrina relief:
If you want to get the best response to a question, please read FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top