XML DOM 教程
1. XML DOM 教程 2. XML DOM 简介 3. XML DOM – 节点 4. XML DOM – 节点树 5. XML DOM 解析器 6. XML DOM 加载函数 7. XML DOM 方法 8. XML DOM 访问节点 9. XML DOM 节点信息 10. XML DOM – 节点列表和命名节点图 11. XML DOM – 遍历节点树 12. XML DOM 浏览器差异 13. XML DOM – 导航节点 14. XML DOM – 获取节点值 15. XML DOM – 改变节点值 16. XML DOM – 删除节点 17. XML DOM – 替换节点 18. XML DOM – 创建节点 19. XML DOM – 添加节点 20. XML DOM – 克隆节点 21. XML DOM – HttpRequest 对象 22. XML DOM – 节点类型 23. XML DOM – Node 对象 24. XML DOM – NodeList 对象 25. XML DOM – NamedNodeMap 对象 26. XML DOM – Document 对象 27. XML DOM – DocumentImplementation 对象 28. XML DOM – DocumentType 对象 29. XML DOM – ProcessingInstruction 对象 30. XML DOM – Element 对象 31. XML DOM – Attr 对象 32. XML DOM – Text 对象 33. XML DOM – CDATASection 对象 34. XML DOM – Comment 对象 35. XML DOM Parse Error 对象 36. XML DOM 解析器错误 37. XML DOM 总结 38. XML DOM 实例 39. XML DOM – 验证 XML

XML DOM – 节点类型

XML DOM 节点类型


DOM 是一个代表节点对象层次的文档。


55面试教程网 - 实例

下面的实例使用 XML 文件 books.xml
函数 loadXMLDoc(),位于外部 JavaScript 中,用于加载 XML 文件。

显示所有元素的 nodeName 和 nodeType

显示所有元素的 nodeName 和 nodeValue


节点类型

下面的表格列举了不同的 W3C 节点类型,每个节点类型中可能会包含子类:

节点类型 描述 子类
Document 代表整个文档(DOM 树的根节点) Element (max. one), ProcessingInstruction, Comment, DocumentType
DocumentFragment 代表"轻量级"的 Document 对象,它可以保留文档中的一部分 Element, ProcessingInstruction, Comment, Text, CDATASection, Entity参考手册
DocumentType 为文档中定义的实体提供了一个接口 None
ProcessingInstruction 代表一个处理指令 None
EntityReference 代表一个实体引用 Element, ProcessingInstruction, Comment, Text, CDATASection, EntityReference
Element 表示一个元素 Element, Text, Comment, ProcessingInstruction, CDATASection, EntityReference
Attr 代表一个属性 Text, EntityReference
Text 代表元素或属性的文本内容 None
CDATASection 代表文档中的 CDATA 区段(文本不会被解析器解析) None
Comment 代表一个注释 None
Entity 代表一个实体 Element, ProcessingInstruction, Comment, Text, CDATASection, EntityReference
Notation 定义一个在 DTD 中声明的符号 None

节点类型 - 返回值

下面的表格列举了每个节点类型(nodetype)所返回的节点名称(nodeName)和节点值(nodeValue):

节点类型 返回的节点名称 返回的节点值
Document #document null
DocumentFragment #document fragment null
DocumentType 文档类型名称 null
Entity参考手册 实体引用名称 null
Element 元素名称 null
Attr 属性名称 属性值
ProcessingInstruction 目标 节点的内容
Comment #comment 注释文本
Text #text 节点的内容
CDATASection #cdata-section 节点的内容
Entity 实体名称 null
Notation 符号名称 null

节点类型 - 命名常量

节点类型 命名常量
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