XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 1st, 2011, 03:36 AM
Adam89 Adam89 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2011
Posts: 3 Adam89 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 46 m 42 sec
Reputation Power: 0
Am I missing something here? (XSD)

Hey everyone,

For the past few days I've been trying to produce an XSD schema that will validate my simple products XML. At first I tried it with the full XML and ran into several issues, so I tried to take things back a step.

For this very simple XML:

Code:
<?xml version="1.0"?>
<products>
    <product>
        <title>Product A</title>
    </product>
</products>


I have this schema:

Code:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="products">
        <xs:sequence>
            <xs:element name="product">
                <xs:sequence>
                    <xs:complexType>
                        <xs:element name="title" type="xs:string" />
                    </xs:complexType>
                </xs:sequence>
            </xs:element>
        </xs:sequence>
    </xs:element>
</xs:schema>


However when I try and validate this using an online tool (tried several), I get back this error message:

Quote:
4s-elt-must-match.1: The content of 'products' must match (annotation?, (simpleType | complexType)?, (unique | key | keyref)*)). A problem was found starting at: sequence.


I feel like I'm missing something really fundamental here, but just can't figure out what?

Edit

I also tried the following schema:

Code:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="products">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="product">
                    <xs:sequence>
                        <xs:complexType>
                            <xs:element name="title" type="xs:string" />
                        </xs:complexType>
                    </xs:sequence>
                </xs:element>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>


Neither work.

Any help would be extremely appreciated!

Thanks

Adam

Reply With Quote
  #2  
Old June 1st, 2011, 10:32 AM
xml-profi xml-profi is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2009
Posts: 190 xml-profi User rank is Sergeant Major (2000 - 5000 Reputation Level)xml-profi User rank is Sergeant Major (2000 - 5000 Reputation Level)xml-profi User rank is Sergeant Major (2000 - 5000 Reputation Level)xml-profi User rank is Sergeant Major (2000 - 5000 Reputation Level)xml-profi User rank is Sergeant Major (2000 - 5000 Reputation Level)xml-profi User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 7 h 8 m 25 sec
Reputation Power: 48
Send a message via ICQ to xml-profi
Code:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
  <xs:element name="products">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="product"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="product">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="title"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="title" type="xs:string"/>
</xs:schema>
__________________
Helmut Hagemann Germany

fallen to the bottom of the facts?
I reach my hand and we go together


wer lesen und google kann ist klar im Vorteil
who read and google is able is clear in the advantage

Reply With Quote
  #3  
Old June 1st, 2011, 10:52 AM
Adam89 Adam89 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2011
Posts: 3 Adam89 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 46 m 42 sec
Reputation Power: 0
Thanks. Looking at that, I'm guessing you can't have a complexType within another?

Reply With Quote
  #4  
Old June 1st, 2011, 11:08 AM
Adam89 Adam89 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2011
Posts: 3 Adam89 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 46 m 42 sec
Reputation Power: 0
Okay I managed to take things a step further, and add in some of the missing values:

Code:
<?xml version="1.0"?>
<products>
    <product>
        <title>Product A</title>
        <stock>
            <available>123</available>
            <ordered>123</ordered>
            <delivery>2011-06-01</delivery>
        </stock>
        <stats>
            <total_sold>123</total_sold>
            <per_order_average>123.12</per_order_average>
            <all_order_average>123.12</all_order_average>
        </stats>
    </product>
</products>


XSD:

Code:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">

    <xs:element name="products">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="product" />
            </xs:sequence>
        </xs:complexType>
    </xs:element>

    <xs:element name="product">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="title" type="xs:string" />
                <xs:element ref="stock" />
                <xs:element ref="stats" />
            </xs:sequence>
        </xs:complexType>
    </xs:element>

    <xs:element name="stock">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="available" type="xs:integer" />
                <xs:element name="ordered" type="xs:integer" />
                <xs:element name="delivery" type="xs:date" />
            </xs:sequence>
        </xs:complexType>
    </xs:element>

    <xs:element name="stats">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="total_sold" type="xs:integer" />
                <xs:element name="per_order_average" type="xs:decimal" />
                <xs:element name="all_order_average" type="xs:decimal" />
            </xs:sequence>
        </xs:complexType>
    </xs:element>

</xs:schema>


This validates! Great stuff. How could I add an attribute to <product> though?

I've tried adding it like:

Code:
    <xs:element name="product">
        <xs:complexType>
            <xs:attribute name="id" type="xs:integer" />


And several other variations, but no luck!

Thanks for your help.

Reply With Quote
  #5  
Old June 1st, 2011, 12:50 PM
xml-profi xml-profi is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2009
Posts: 190 xml-profi User rank is Sergeant Major (2000 - 5000 Reputation Level)xml-profi User rank is Sergeant Major (2000 - 5000 Reputation Level)xml-profi User rank is Sergeant Major (2000 - 5000 Reputation Level)xml-profi User rank is Sergeant Major (2000 - 5000 Reputation Level)xml-profi User rank is Sergeant Major (2000 - 5000 Reputation Level)xml-profi User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 7 h 8 m 25 sec
Reputation Power: 48
Send a message via ICQ to xml-profi
Code:
<xs:element name="product">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="title"/>
      </xs:sequence>
	  <xs:attribute ref="id" use="required"/>
    </xs:complexType>
	
  </xs:element>
  
  <xs:attribute name="id" type="xs:integer"/>

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > Am I missing something here? (XSD)

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap