• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

XSD Definition For XML

 
Greenhorn
Posts: 19
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I am trying to define a schema (xsd) for the following xml.



The "Team" element has an attribute "desc" of type String.
Within the "Team" element there are further elements ( one to many ) of type "Player".

The "Player" element has a "number" attributes of type String ( 1,2, etc ) and
holds a type String ( Gordan Banks, George Best, etc )


I used the http://xmlgrid.net/xml2xsd.html to get the XSD for the XML :-



I than used http://www.freeformatter.com/xml-validator-xsd.html to effectively validate the xsd and xml.

However, I am encountering the following error :-

Src-element.3: Element 'Player' Has Both A 'type' Attribute And A 'anonymous Type' Child. Only One Of These Is Allowed For An Element.



How can I address this error or is there alternative XSD definition that I can use which adheres to the XML.

Any suggestion would be appreciated. Thank you.

Regards
Pete.



 
Ranch Hand
Posts: 734
7
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


You cannot have xs:element having a type attribute defined
and then followed by an xs:complexType or xs:simpleType for that matter, you can only have a construction one kind or another. That's what the error message meant.

The prime way of doing it is to do an extension of a complexType element with simpleContent. Like this.

There may have shortcut and there does, but the idea is there in an elaborated display.
 
Pete Long
Greenhorn
Posts: 19
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi g tsuji,

Thanks for pointing me in the right direction. Very much appreciated

Below is the valid and working xsd for the example xml I provided.



Pete
 
Tell me how it all turns out. Here is a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic