473,371 Members | 1,507 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,371 software developers and data experts.

XSD: What is the root element

If I define more than one element "globally" in an XML schema, is there any
hint which one is the actual root element for any instance document?
e.g.
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="a">
<xs:complexType>
<xs:sequence>
<xs:element ref="b"/>
<xs:element name="c"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="b"/>
</xs:schema>

allows two valid instance documents. First is

<?xml version="1.0" encoding="UTF-8"?>
<a>
<b>Text</b>
<c>Text</c>
</a>

Second is simply
<?xml version="1.0" encoding="UTF-8"?>
<b/>

Of course a is meant as root element but I want to use global elements for
reuse however. How can I avoid this ambiguousity?

Thank you.
Sascha
Aug 16 '05 #1
3 3226
On Tue, 16 Aug 2005 20:41:16 +0200, "Sascha Kerschhofer"
<sk**********@yahoo.antispam.de> wrote:
If I define more than one element "globally" in an XML schema, is there any
hint which one is the actual root element for any instance document?
e.g.
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="a">
<xs:complexType>
<xs:sequence>
<xs:element ref="b"/>
<xs:element name="c"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="b"/>
</xs:schema>

allows two valid instance documents. First is

<?xml version="1.0" encoding="UTF-8"?>
<a>
<b>Text</b>
<c>Text</c>
</a>

Second is simply
<?xml version="1.0" encoding="UTF-8"?>
<b/>

Of course a is meant as root element but I want to use global elements for
reuse however. How can I avoid this ambiguousity?


There's no way in an xsd to say which globally defined element or elements may
or may not be the root element. Many reputable people say that, for that
reason you should use types to slice up the design layers, and not define
multiple global elements. Personally, I disagree - I think defining many
global elements in an xsd is the best design approach, in spite of the root
element problem.

What OASIS says on the subject is to add a documentation annotation to the
root element definition stating that it is the one and only element for use as
a root. I also like to make an annotation at the top, schema level stating
that there is only one root element, and says which element that is.
Aug 17 '05 #2
Some schema processors, including XSV [1], take a command line or
invocation argument allowing you to specify a name you want to be
required for the document element.

ht

[1] http://www.ltg.ed.ac.uk/~ht/xsv-status.html
--
Henry S. Thompson, HCRC Language Technology Group, University of Edinburgh
Half-time member of W3C Team
2 Buccleuch Place, Edinburgh EH8 9LW, SCOTLAND -- (44) 131 650-4440
Fax: (44) 131 650-4587, e-mail: ht@inf.ed.ac.uk
URL: http://www.ltg.ed.ac.uk/~ht/
[mail really from me _always_ has this .sig -- mail without it is forged spam]
Aug 17 '05 #3
On Wed, 17 Aug 2005 13:22:17 +0100, ht@inf.ed.ac.uk (Henry S. Thompson) wrote:
Some schema processors, including XSV [1], take a command line or
invocation argument allowing you to specify a name you want to be
required for the document element.

ht

[1] http://www.ltg.ed.ac.uk/~ht/xsv-status.html


I'm not sure how helpful that is vs having the application check the root
element name after parsing. It saves taking the time to fully invalidate and
load a useless document, but it won't stop an author from using your schema to
validate that same document successfully.
Aug 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: yaya9 | last post by:
pls help me! I have a nested xml: <?xml version="1.0" encoding="utf-8" ?> <root> <myType> <FName /> <pop /> </myType> </root>
1
by: aevans1108 | last post by:
Greetings All If this is the wrong place to post this question, please give me a push in the right direction. Thanks. I know there has to be a simpler way to do this, but this is as simple a...
9
by: Eskimo | last post by:
I get "The attribute targetNamespace does not match the designated namespace URI" and nothing else. I have an xml file, that was pre-existing. I have to validate against the schema provided, I...
2
by: PeterW | last post by:
I have an xml file from which I want to generate an xsd schema and at a later stage a cs class. The xml file has a mix of defined namespaces and also an empty namespace. These are defined as...
2
by: farseer | last post by:
Hi, First, sorry for this long post, but i'd like to explain my problem in detail... i have generated some classes from my schema. Classes are generated for the root (overall document),...
4
by: Jonas Bush | last post by:
I've got the some code to try and validate some xml. Against my schema, the "Good" xml (below) produces a couple of warnings, which I don't care about. The "Bad" xml (also below), produces warnings...
0
by: Dave Hill | last post by:
Forgive a newbie question. I'm learning the .NET XML environment. In the walkthrough on using XML designer to create an xsd, there is no discussion of the root element of the target xml document....
2
by: =?Utf-8?B?TWlnaHR5IE1hcms=?= | last post by:
I'd like to generate my WebService interface from an XSD schema. Here's what I've done: 1. created a XML file 2. use the xsd.exe to generate the XSD: C:\>xsd my.xml 3. my.xsd is generated 4....
4
by: BorisBoshond | last post by:
Hi all, Hope someone is able and willing to help me with following problem. I received a xsd file from another company, our company i supposed to return xml based on that xsd. Problem is that I...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.