• 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

xml schema: child elements in "choice"

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is it possible to have such a combination in xml schema:
<element name="xyz">
<complexType>
<choice>
<element name="child1">
<simpleType>
<restriction base="string">
<enumeration>abcd</enumeration>
</restriction>
</simpleType>
</element>
</choice>
<element name="child1">
<simpleType>
<restriction base="string">
<enumeration>pqrs</enumeration>
</restriction>
</simpleType>
</element>
</complexType>
</element>
 
author and deputy
Posts: 3150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can always use some IDE's like XMLSPY or TURBO XML etc., to check this.
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No Kiran,
Its not possible to have the kind of arrangement that you've shown in your schema. First, you can't have an <element> directly under the <complexType> element. And you can have only one compositor (xsd:choice, xsd:sequence or xsd:all) directly under the <complexType> element. So, you'll have to put both the <element> tags in the <choice> tag, and that would be wrong since their names would clash and the validator would complain about 'redefinition'.
So, you can't have more than one declarations (of varying types) of elements in the same scope. If the types were the same, then it would've been okay.
BTW, this applies to attributes and types too.
Hope I've made some sense.
Dhananjay.
 
D Kiran Kumar
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for the replies.
I'd like to add a correction in Dhananjay's reply.
As it turned out, the parser does not allow a repititive definition even if it is same at the local level. This, I found out when validating with xerces parser. xml spy does not throw this error.
Thanks,
D. Kiran Kumar
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic