XML DOM 節(jié)點(diǎn)類(lèi)型(Node Types)
實(shí)例
在下面的例子中,我們將使用 XML 文件 books.xml,以及 JavaScript 函數(shù) loadXMLDoc()。
節(jié)點(diǎn)類(lèi)型
下面的表格列出了不同的 W3C 節(jié)點(diǎn)類(lèi)型,以及它們可擁有的子元素:
節(jié)點(diǎn)類(lèi)型 | 描述 | 子元素 |
---|---|---|
Document | 表示整個(gè)文檔(DOM 樹(shù)的根節(jié)點(diǎn)) |
|
DocumentFragment | 表示輕量級(jí)的 Document 對(duì)象,其中容納了一部分文檔。 |
|
DocumentType | 向?yàn)槲臋n定義的實(shí)體提供接口。 | None |
ProcessingInstruction | 表示處理指令。 | None |
EntityReference | 表示實(shí)體引用元素。 |
|
Element | 表示 element(元素)元素 |
|
Attr | 表示屬性。 |
|
Text | 表示元素或?qū)傩灾械奈谋緝?nèi)容。 | None |
CDATASection | 表示文檔中的 CDATA 區(qū)段(文本不會(huì)被解析器解析) | None |
Comment | 表示注釋。 | None |
Entity | 表示實(shí)體。 |
|
Notation | 表示在 DTD 中聲明的符號(hào)。 | None |
節(jié)點(diǎn)類(lèi)型 - 所返回的值
下面的表格列出了對(duì)每個(gè)節(jié)點(diǎn)類(lèi)型來(lái)說(shuō),nodeName 和 nodeValue 屬性可返回的值:
節(jié)點(diǎn)類(lèi)型 | nodeName 的返回值 | nodeValue 的返回值 |
---|---|---|
Document | #document | null |
DocumentFragment | #document fragment | null |
DocumentType | doctype 名稱(chēng) | null |
EntityReference | 實(shí)體引用名稱(chēng) | null |
Element | element name | null |
Attr | 屬性名稱(chēng) | 屬性值 |
ProcessingInstruction | target | 節(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 |
NodeTypes - 有名常數(shù)
NodeType | Named Constant |
---|---|
1 | ELEMENT_NODE |
2 | ATTRIBUTE_NODE |
3 | TEXT_NODE |
4 | CDATA_SECTION_NODE |
5 | ENTITY_REFERENCE_NODE |
6 | ENTITY_NODE |
7 | PROCESSING_INSTRUCTION_NODE |
8 | COMMENT_NODE |
9 | DOCUMENT_NODE |
10 | DOCUMENT_TYPE_NODE |
11 | DOCUMENT_FRAGMENT_NODE |
12 | NOTATION_NODE |