Been looking at a tutorial and it has the following xml and xsd.:
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>
XML Documents Must Have a Root Element.
Datatype requirements The XML schema language must: provide for primitive data typing, including byte, date, integer, sequence, SQL & Java primitive data types, etc.; Conformance.
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.
XSD - The <schema> Element The <schema> element is the root element of every XML Schema.
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.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With