Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do you always have to have a root node with xml/xsd?

Tags:

xml

xsd

Been looking at a tutorial and it has the following xml and xsd.:

http://yfrog.com/b9xsdandxmlj

What I was wondering is do you have to use a root node in this example? There doesnt seem to be any xsd type definition that points to the 'employeeS' node.

Do you always have to have a root node in xml or can you just have

<xml version="1.0">
<employee><employee>
<employee><employee>
<employee><employee>
like image 794
Exitos Avatar asked Nov 29 '10 13:11

Exitos


People also ask

Is root element mandatory in XML?

XML Documents Must Have a Root Element.

What is the requirement of XML Schema?

Datatype requirements The XML schema language must: provide for primitive data typing, including byte, date, integer, sequence, SQL & Java primitive data types, etc.; Conformance.

How does XSD work with XML?

XSD is based and written on XML. XSD defines elements and structures that can appear in the document, while XML does not. XSD ensures that the data is properly interpreted, while XML does not. An XSD document is validated as XML, but the opposite may not always be true.

What is the root element in XSD?

XSD - The <schema> Element The <schema> element is the root element of every XML Schema.


2 Answers

from the XML specification at http://www.w3.org/TR/REC-xml/ (fifth edition) chapter 2

This says

"Each XML document has both a logical and a physical structure. Physically, the document is composed of units called entities. An entity may refer to other entities to cause their inclusion in the document. A document begins in a "root" or document entity."

"[Definition: There is exactly one element, called the root, or document element, no part of which appears in the content of any other element.] For all other elements, if the start-tag is in the content of another element, the end-tag is in the content of the same element. More simply stated, the elements, delimited by start- and end-tags, nest properly within each other."

So basically yes, you always need one root element.

like image 172
Guy Avatar answered Oct 21 '22 06:10

Guy


Yes, you always have to have a root node. However, you can have a file that holds an XML document fragment that is imported into another file as a parsed entity. All the including file needs to do is have a declaration like this in its DTD:

<!ENTITY SomeName SYSTEM "/path/to/file.xml">

Then it can just wrap it up like this:

<SomeOuterTag>
   &SomeName;
</SomeOuterTag>
like image 21
Donal Fellows Avatar answered Oct 21 '22 05:10

Donal Fellows