nodeType Property
Specifies the XML Document Object Model (DOM) node type, which determines valid values and whether the node can have child nodes.
Script Syntax
lValue = oXMLDOMNode.nodeType;
Example
The following script example creates an IXMLDOMNode
object and displays its type enumeration, in this case, 1 for NODE_ELEMENT.
var xmlDoc = new ActiveXObject5.0("Msxml2.DOMDocument.5.0"); var currNode; xmlDoc.async = false; xmlDoc.load("books.xml"); if (xmlDoc.parseError.errorCode != 0) { var myErr = xmlDoc.parseError; alert("You have error " + myErr.reason); } else { currNode = xmlDoc.documentElement.childNodes.item(0); alert(currNode.nodeType); }
Visual Basic Syntax
lValue = oXMLDOMNode.nodeType
Example
The following Microsoft® Visual Basic® example creates an IXMLDOMNode
object and displays its type enumeration, in this case, 1 for NODE_ELEMENT.
Dim xmlDoc As New Msxml2.DOMDocument50 Dim currNode As IXMLDOMNode xmlDoc.async = False xmlDoc.Load ("books.xml") If (xmlDoc.parseError.errorCode <> 0) Then Dim myErr Set myErr = xmlDoc.parseError MsgBox("You have error " & myErr.reason) Else Set currNode = xmlDoc.documentElement.childNodes.Item(0) MsgBox currNode.nodeType End If
C/C++ Syntax
HRESULT get_nodeType( DOMNodeType *type);
Parameters
- type [out, retval]
- Type of the node.
C/C++ Return Values
- S_OK
- Value returned if successful.
- E_INVALIDARG
- Value returned if the
type
parameter is Null.
Remarks
Enumeration. The property is read-only. It indicates the type of the node. Use the nodeTypeString
property to return the node type in string form.
The IXMLDOMNodeType
enumeration defines the following valid values that can appear in the nodeType
property.
NODE_ELEMENT (1) | The node represents an element. An element node can have the following child node types: Element, Text, Comment, ProcessingInstruction, CDATASection, and EntityReference. An element node can be the child of the Document, DocumentFragment, EntityReference, and Element nodes. |
NODE_ATTRIBUTE (2) | The node represents an attribute of an element. An attribute node can have the following child node types: Text and EntityReference. An attribute does not appear as the child node of any other node type; note that it is not considered a child node of an element. |
NODE_TEXT (3) | The node represents the text content of a tag. A text node cannot have any child nodes. A text node can appear as the child node of the Attribute, DocumentFragment, Element, and EntityReference nodes. |
NODE_CDATA_SECTION (4) | The node represents a CDATA section in the XML source. CDATA sections are used to escape blocks of text that would otherwise be recognized as markup. A CDATA section node cannot have any child nodes. A CDATA section node can appear as the child of the DocumentFragment, EntityReference, and Element nodes. |
NODE_ENTITY_REFERENCE (5) | The node represents a reference to an entity in the XML document. This applies to all entities, including character entity references. An entity reference node can have the following child node types: Element, ProcessingInstruction, Comment, Text, CDATASection, and EntityReference. An entity reference node can appear as the child of the Attribute, DocumentFragment, Element, and EntityReference nodes. |
NODE_ENTITY (6) | The node represents an expanded entity. An entity node can have child nodes that represent the expanded entity (for example, Text and EntityReference nodes). An entity node can appear as the child of the DocumentType node. |
NODE_PROCESSING_INSTRUCTION (7) | The node represents a processing instruction from the XML document. A processing instruction node cannot have any child nodes. A processing instruction node can appear as the child of the Document, DocumentFragment, Element, and EntityReference nodes. |
NODE_COMMENT (8) | The node represents a comment in the XML document. A comment node cannot have any child nodes. A comment node can appear as the child of Document, DocumentFragment, Element, and EntityReference nodes. |
NODE_DOCUMENT (9) | The node represents a document object, which, as the root of the document tree, provides access to the entire XML document. It is created using the progID "Msxml2.DOMDocument", or through a data island using <XML> or <SCRIPT LANGUAGE=XML> . A document node can have the following child node types: Element (maximum of one), ProcessingInstruction, Comment, and DocumentType. A document node cannot appear as the child of any node types. |
NODE_DOCUMENT_TYPE (10) | The node represents the document type declaration, indicated by the <!DOCTYPE > tag. A document type node can have the following child node types: Notation and Entity. A document type node can appear as the child of the Document node. |
NODE_DOCUMENT_FRAGMENT (11) | The node represents a document fragment. A document fragment node associates a node or subtree with a document without actually being contained within the document. A document fragment node can have the following child node types: Element, ProcessingInstruction, Comment, Text, CDATASection, and EntityReference. A DocumentFragment node cannot appear as the child of any node types. |
NODE_NOTATION (12) | A node represents a notation in the document type declaration. A notation node cannot have any child nodes. A notation node can appear as the child of the DocumentType node. |
To view reference information for Visual Basic, C/C++, or Script only, click the Language Filter button in the upper-left corner of the page.
See Also
Applies to: IXMLDOMAttribute | IXMLDOMCDATASection | IXMLDOMCharacterData | IXMLDOMComment | DOMDocument | IXMLDOMDocumentFragment | IXMLDOMDocumentType | IXMLDOMElement | IXMLDOMEntity | IXMLDOMEntityReference | IXMLDOMNode | IXMLDOMNotation | IXMLDOMProcessingInstruction | IXMLDOMText | XML DOM Enumerated Constants