Solved

Creating XSD

Posted on 2011-03-02
4
309 Views
Last Modified: 2012-05-11
I'm trying to create an XSD for my XML structure, but I'm not sure this is right, I need a little help in the right direction.

My XSD is
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
	<xs:element name="ContactDetails" type="Contact"/>

	<xs:complexType name="Contact">
	  <xs:sequence>
		<xs:element name="Surname" type="xs:string"/>
		<xs:element name="Firstname" type="xs:string"/>
		<xs:sequence>
			<xs:element name="Addresses" type="Address"/>
		</xs:sequence>
	  </xs:sequence>
	</xs:complexType>

	<xs:complexType name="Address">
	  <xs:sequence>
		  <xs:element name="Line1" type="xs:string"/>
		  <xs:element name="Line2" type="xs:string"/>
	  </xs:sequence>
	</xs:complexType>
	
</xs:schema>

Open in new window


Which when I 'generate xml sample' produces me this in VS2010

<?xml version="1.0" encoding="utf-8"?>
<ContactDetails>
  <Surname>Surname1</Surname>
  <Firstname>Firstname1</Firstname>
  <Addresses>
    <Line1>Line11</Line1>
    <Line2>Line21</Line2>
  </Addresses>
</ContactDetails>

Open in new window


But what I'm after is actually this

<?xml version="1.0" encoding="utf-8"?>
<ContactDetails>
  <Surname>Surname1</Surname>
  <Firstname>Firstname1</Firstname>
  <Addresses>
    <Address>
       <Line1>Line11</Line1>
       <Line2>Line21</Line2>
    </Address>
    <Address>
       <Line1>Line12</Line1>
       <Line2>Line22</Line2>
    </Address>
  </Addresses>
</ContactDetails>

Open in new window


What am I doing wrong in my XSD?

Thanks! ^_^
0
Comment
Question by:Narusegawa
  • 2
  • 2
4 Comments
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 500 total points
ID: 35019834
You forgot one layer
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="ContactDetails" type="Contact"/>
    
    <xs:complexType name="Contact">
        <xs:sequence>
            <xs:element name="Surname" type="xs:string"/>
            <xs:element name="Firstname" type="xs:string"/>
            <xs:sequence>
                <xs:element name="Addresses" >
                    <xs:complexType>
                        <xs:sequence maxOccurs="unbounded">
                            <xs:element name="Address" type="Address"/>
                        </xs:sequence>
                    </xs:complexType>
                </xs:element>
            </xs:sequence>
        </xs:sequence>
    </xs:complexType>
    
    <xs:complexType name="Address">
        <xs:sequence>
            <xs:element name="Line1" type="xs:string"/>
            <xs:element name="Line2" type="xs:string"/>
        </xs:sequence>
    </xs:complexType>
    
</xs:schema>

Open in new window

0
 

Author Closing Comment

by:Narusegawa
ID: 35021152
Perfect!
0
 

Author Comment

by:Narusegawa
ID: 35021160
Thanks very much for that! It makes sense now.
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 35022175
welcome
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now