?
Solved

Creating XSD

Posted on 2011-03-02
4
Medium Priority
?
314 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 2000 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

801 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