• 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

Multiple root elements in a XML schema

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

I have a question on multiple roots in a XML schema.

- IN xml schema <schema> element is the root element
now when we say its valid to have multiple roots in a xml schema , does this mean we can have more than one <schema> element in a XML schema file.

- in the below code
<xs:schema xmlns=""
tagetNamespace=""
elementFormDefault="qualified">

<xs:element name="transId" type="xs:string"/>
</schema>

transId i suppose is a global element, does this also mean as per schema it can be a the root element too. is this a case of multiple roots

Thanks!
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
An XML document -- any XML document -- can only have one root element. This includes XML Schema documents, XHTML documents, XSL documents, everything. They all can have exactly 1 root element or they won't be parsed by any XML parser.

I didn't quite understand what you mean by the question about transId?
 
dinaker prasad
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My understanding was there cannot be more than one root in an XML or XSD file.
The below text is reply to a question in a different forum where the person mentions its valid to have multiple roots in a XSD document

please read the below message.
---------------------------------------------------------------------------
Any valid XML document instance has a single root element. The schema
allows you define multiple alternative roots because that's a valid
scenario (it assumes that it's a choice between the possible roots). For
instance, the following 2 documents will validate against your schema
---------------------------------------------------------------------------


is that valid that schema allows you to define multiple alternative roots.


thanks
Dinaker
 
Lasse Koskela
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ah. True. While the XSD document must have only one root element, it can describe an XML document in such a way that the XML document may have one of multiple allowed root elements.
 
sunglasses are a type of coolness prosthetic. Check out the sunglasses on this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic