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

后端 未结 5 941
抹茶落季
抹茶落季 2020-12-03 11:49

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

\"http://yfrog.com/b9xsdandxmlj\"

Wha

相关标签:
5条回答
  • 2020-12-03 12:30

    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>
    
    0 讨论(0)
  • 2020-12-03 12:31

    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)

    0 讨论(0)
  • 2020-12-03 12:33

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

    0 讨论(0)
  • 2020-12-03 12:42

    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.

    0 讨论(0)
  • 2020-12-03 12:49

    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.

    0 讨论(0)
提交回复
热议问题