您是否总是需要一个具有xml/xsd的根节点?

时间:2022-12-28 17:16:32

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

一直在看教程,它有以下xml和xsd。

您是否总是需要一个具有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.

我想知道的是,在这个示例中,您是否必须使用根节点?似乎没有任何指向“employeeS”节点的xsd类型定义。

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

您是否总是需要在xml中有根节点

<xml version="1.0">
<employee><employee>
<employee><employee>
<employee><employee>

5 个解决方案

#1


9  

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

来自http://www.w3.org/TR/REC-xml/(第五版)第2章的XML规范

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."

每个XML文档都有逻辑结构和物理结构。在物理上,文档由称为实体的单元组成。实体可以引用其他实体以使其包含在文档中。文档以“根”或文档实体开始。

"[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."

[定义:只有一个元素,称为根元素,或文档元素,没有任何部分出现在任何其他元素的内容中。对于所有其他元素,如果start标记位于另一个元素的内容中,则end标记位于同一元素的内容中。更简单地说,由开始和结束标记分隔的元素相互嵌套。

So basically yes, you always need one root element.

基本上是,你总是需要一个根元素。

#2


2  

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:

是的,你总是需要一个根节点。但是,您可以有一个包含XML文档片段的文件,它作为解析实体导入到另一个文件中。所包含的文件所需要做的就是在它的DTD中有这样的声明:

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

Then it can just wrap it up like this:

然后它可以这样结束:

<SomeOuterTag>
   &SomeName;
</SomeOuterTag>

#3


2  

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

*上对XML的简要描述总结了官方XML规范中的几个格式良好的规则:

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

有一个包含所有其他元素的“根”元素。

#4


1  

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

根节点是强制性的。在W3C的命名法中,它也被称为“文档元素”。

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)

定义:只有一个元素,称为根元素,或文档元素,没有任何部分出现在其他元素的内容中(引用:W3C XML规范的第2.1节)

#5


0  

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

是的,您需要有一个根节点,而且只有一个根节点。

#1


9  

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

来自http://www.w3.org/TR/REC-xml/(第五版)第2章的XML规范

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."

每个XML文档都有逻辑结构和物理结构。在物理上,文档由称为实体的单元组成。实体可以引用其他实体以使其包含在文档中。文档以“根”或文档实体开始。

"[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."

[定义:只有一个元素,称为根元素,或文档元素,没有任何部分出现在任何其他元素的内容中。对于所有其他元素,如果start标记位于另一个元素的内容中,则end标记位于同一元素的内容中。更简单地说,由开始和结束标记分隔的元素相互嵌套。

So basically yes, you always need one root element.

基本上是,你总是需要一个根元素。

#2


2  

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:

是的,你总是需要一个根节点。但是,您可以有一个包含XML文档片段的文件,它作为解析实体导入到另一个文件中。所包含的文件所需要做的就是在它的DTD中有这样的声明:

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

Then it can just wrap it up like this:

然后它可以这样结束:

<SomeOuterTag>
   &SomeName;
</SomeOuterTag>

#3


2  

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

*上对XML的简要描述总结了官方XML规范中的几个格式良好的规则:

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

有一个包含所有其他元素的“根”元素。

#4


1  

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

根节点是强制性的。在W3C的命名法中,它也被称为“文档元素”。

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)

定义:只有一个元素,称为根元素,或文档元素,没有任何部分出现在其他元素的内容中(引用:W3C XML规范的第2.1节)

#5


0  

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

是的,您需要有一个根节点,而且只有一个根节点。