我正在阅读一本电子书,它具有以下 xml 代码。
<?xml version="1.0"?>
<?xml-stylesheet href="sonnet.xsl" type="text/xsl"?>
<?cocoon-process type="xslt"?>
<!DOCTYPE sonnet [
<!ELEMENT sonnet (auth:author, title, lines)>
<!ATTLIST sonnet public-domain CDATA "yes"
type (Shakespearean | Petrarchan) "Shakespearean">
<!ELEMENT auth:author (last-name,first-name,nationality,
year-of-birth?,year-of-death?)>
<!ELEMENT last-name (#PCDATA)>
<!ELEMENT first-name (#PCDATA)>
<!ELEMENT nationality (#PCDATA)>
<!ELEMENT year-of-birth (#PCDATA)>
<!ELEMENT year-of-death (#PCDATA)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT lines (line,line,line,line,
line,line,line,line,line,line,line,
line,line,line)>
<!ELEMENT line (#PCDATA)>
]>
<!-- Default sonnet type is Shakespearean, the other allowable -->
<!-- type is "Petrarchan." -->
<sonnet type="Shakespearean">
<auth:author xmlns:auth="http://www.authors.com/">
<last-name>Shakespeare</last-name>
<first-name>William</first-name>
<nationality>British</nationality>
<year-of-birth>1564</year-of-birth>
<year-of-death>1616</year-of-death>
</auth:author>
<!-- Is there an official title for this sonnet? They're
sometimes named after the first line. -->
<title>Sonnet 130</title>
<lines>
<line>My mistress' eyes are nothing like the sun,</line>
<line>Coral is far more red than her lips red.</line>
<line>If snow be white, why then her breasts are dun,</line>
<line>If hairs be wires, black wires grow on her head.</line>
<line>I have seen roses damasked, red and white,</line>
<line>But no such roses see I in her cheeks.</line>
<line>And in some perfumes is there more delight</line>
<line>Than in the breath that from my mistress reeks.</line>
<line>I love to hear her speak, yet well I know</line>
<line>That music hath a far more pleasing sound.</line>
<line>I grant I never saw a goddess go,</line>
<line>My mistress when she walks, treads on the ground.</line>
<line>And yet, by Heaven, I think my love as rare</line>
<line>As any she belied with false compare.</line>
</lines>
</sonnet>
<!-- The title of Sting's 1987 album "Nothing like the sun" is -->
<!-- from line 1 of this sonnet.
问题是当我继续阅读其余部分时,我以为我误解了根元素是什么。根据我的知识,根节点是<sonnet>
节点。
但在书中我发现下一个
与其他节点不同,根节点没有父节点。它总是至少有一个子元素,即文档元素。根节点还包含文档元素之外的注释或处理指令。在我们的示例文档中,名为 xmlstylesheet 和 cocoon-process 的两个处理指令都是根节点的子节点,出现在标记之前的注释和出现在标记之后的注释也是如此。
根据该整个文档被视为根。如果是的话是什么?很明显,处理指令和注释不是节点的子节点。
我明白了吗?
更新
<?xml version="1.0"?>
<Food>
<Cateogry> Vegetable</Cateogry>
<Cateogry> Fruits</Cateogry>
<Cateogry> other</Cateogry>
</Food>
这里的根元素是什么?不是食物吗?