Solved

Creating XSD

Posted on 2011-03-02
4
310 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

786 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