XML DOM tutoria...login
XML DOM tutorial
author:php.cn  update time:2022-04-13 15:27:56

DOM node type


XML DOM Node type


DOM is a document that represents a hierarchy of node objects.


tryitimg.gifTry it out - Example


The example below uses the XML file books.xml.
Function loadXMLDoc(), located in external JavaScript, is used to load XML files.

Display the nodeName and nodeType of all elements

Display the nodeName and nodeValue of all elements


Node type

The following table lists the different W3C node types, each node type may contain subclasses:

##EntityRepresents an entityElement, ProcessingInstruction, Comment, Text, CDATASection, EntityReferenceNotationDefine a symbol declared in the DTDNone

Node type - return value

The following table lists the node name (nodeName) and node value (nodeValue) returned by each node type (nodetype):

Node typeDescriptionSubclass
DocumentRepresents the entire document (the root node of the DOM tree) Element (max. one), ProcessingInstruction, Comment, DocumentType
DocumentFragmentRepresents a "lightweight" Document object, which can retain a part of the documentElement, ProcessingInstruction, Comment, Text, CDATASection, Entity Reference Manual
DocumentTypeProvides an interface for entities defined in documentsNone
ProcessingInstructionRepresents a processing instructionNone
EntityReferenceRepresents an entity referenceElement, ProcessingInstruction, Comment, Text, CDATASection, EntityReference
Element represents an elementElement, Text, Comment, ProcessingInstruction, CDATASection, EntityReference
Attr represents an attribute Text, EntityReference
TextRepresents the text content of the element or attributeNone
CDATASectionRepresents the CDATA section in the document (the text will not be parsed by the parser) None
Comment represents a comment None
##AttrAttribute name Attribute valueProcessingInstructionTargetContent of nodeComment #commentComment textText#textContent of nodeCDATASection#cdata-sectionContent of nodeEntityEntity namenull NotationSymbol Namenull
Node typeReturned node nameReturned node value
Document#documentnull
DocumentFragment#document fragmentnull
DocumentTypeDocument type namenull
Entity Reference ManualEntity reference namenull
ElementElement namenull
Node Type - Named Constant

Node typeNamed constant1ELEMENT_NODE2ATTRIBUTE_NODE3TEXT_NODE4CDATA_SECTION_NODE5ENTITY_REFERENCE_NODE##678910##11DOCUMENT_FRAGMENT_NODE12NOTATION_NODE
ENTITY_NODE
PROCESSING_INSTRUCTION_NODE
COMMENT_NODE
DOCUMENT_NODE
DOCUMENT_TYPE_NODE