开发者

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

开发者 https://www.devze.com 2023-01-28 12:17 出处:网络
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 definit

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

Do you always have to have a root node with xml/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>


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>


From the brief description of XML at Wikipedia, which summarizes several well-formedness rules from the official XML spec:

There is a single "root" element which contains all the other elements.


Root node is mandatory. It's also referred to as "Document Element" in W3C's nomenclature.

Definition: There is exactly one element, called the root, or document element, no part of which appears in the content of any other element (reference: section 2.1 of W3C XML specs)


Yes, you are required to have one, and only one root node.

0

精彩评论

暂无评论...
验证码 换一张
取 消