XML DOM 節(jié)點(diǎn)類(lèi)型


DOM 是一個(gè)代表節(jié)點(diǎn)對(duì)象層次的文檔。


tryitimg.gif嘗試一下 - 實(shí)例


下面的實(shí)例使用 XML 文件 books.xml。
函數(shù) loadXMLDoc(),位于外部 JavaScript 中,用于加載 XML 文件。

顯示所有元素的 nodeName 和 nodeType

顯示所有元素的 nodeName 和 nodeValue


節(jié)點(diǎn)類(lèi)型

下面的表格列舉了不同的 W3C 節(jié)點(diǎn)類(lèi)型,每個(gè)節(jié)點(diǎn)類(lèi)型中可能會(huì)包含子類(lèi):

節(jié)點(diǎn)類(lèi)型描述子類(lèi)
Document代表整個(gè)文檔(DOM 樹(shù)的根節(jié)點(diǎn))Element (max. one), ProcessingInstruction, Comment, DocumentType
DocumentFragment代表"輕量級(jí)"的 Document 對(duì)象,它可以保留文檔中的一部分Element, ProcessingInstruction, Comment, Text, CDATASection, Entity參考手冊(cè)
DocumentType為文檔中定義的實(shí)體提供了一個(gè)接口None
ProcessingInstruction代表一個(gè)處理指令None
EntityReference代表一個(gè)實(shí)體引用Element, ProcessingInstruction, Comment, Text, CDATASection, EntityReference
Element表示一個(gè)元素Element, Text, Comment, ProcessingInstruction, CDATASection, EntityReference
Attr代表一個(gè)屬性Text, EntityReference
Text代表元素或?qū)傩缘奈谋緝?nèi)容None
CDATASection代表文檔中的 CDATA 區(qū)段(文本不會(huì)被解析器解析)None
Comment代表一個(gè)注釋None
Entity代表一個(gè)實(shí)體Element, ProcessingInstruction, Comment, Text, CDATASection, EntityReference
Notation定義一個(gè)在 DTD 中聲明的符號(hào)None

節(jié)點(diǎn)類(lèi)型 - 返回值

下面的表格列舉了每個(gè)節(jié)點(diǎn)類(lèi)型(nodetype)所返回的節(jié)點(diǎn)名稱(chēng)(nodeName)和節(jié)點(diǎn)值(nodeValue):

節(jié)點(diǎn)類(lèi)型返回的節(jié)點(diǎn)名稱(chēng)返回的節(jié)點(diǎn)值
Document#documentnull
DocumentFragment#document fragmentnull
DocumentType文檔類(lèi)型名稱(chēng)null
Entity參考手冊(cè)實(shí)體引用名稱(chēng)null
Element元素名稱(chēng)null
Attr屬性名稱(chēng)屬性值
ProcessingInstruction目標(biāo)節(jié)點(diǎn)的內(nèi)容
Comment#comment注釋文本
Text#text節(jié)點(diǎn)的內(nèi)容
CDATASection#cdata-section節(jié)點(diǎn)的內(nèi)容
Entity實(shí)體名稱(chēng)null
Notation符號(hào)名稱(chēng)null

節(jié)點(diǎn)類(lèi)型 - 命名常量

節(jié)點(diǎn)類(lèi)型命名常量
1ELEMENT_NODE
2ATTRIBUTE_NODE
3TEXT_NODE
4CDATA_SECTION_NODE
5ENTITY_REFERENCE_NODE
6ENTITY_NODE
7PROCESSING_INSTRUCTION_NODE
8COMMENT_NODE
9DOCUMENT_NODE
10DOCUMENT_TYPE_NODE
11DOCUMENT_FRAGMENT_NODE
12NOTATION_NODE