Microsoft XML Core Services (MSXML) 5.0 for Microsoft Office - DOM Reference

nodeValue Property

Contains the text associated with the node.

[Script]

Script Syntax

objValue = oXMLDOMNode.nodeValue;
objXMLDOMNode.nodeValue = objValue;

Example

The following script example creates an IXMLDOMNode object and tests if it is a comment node. If it is, it displays its value.

var xmlDoc = new ActiveXObject5.0("Msxml2.DOMDocument.5.0");
var currNode;
xmlDoc.async = false;
xmlDoc.loadXML("<root><!-- Hello --></root>");
if (xmlDoc.parseError.errorCode <> 0) {
   var myErr = xmlDoc.parseError;
   alert("You have error " + myErr.reason);
} else {
   currNode = xmlDoc.documentElement.childNodes.item(0);
   if (currNode.nodeTypeString == "comment") {
      alert(currNode.nodeValue);
   }
}
[Visual Basic]

Visual Basic Syntax

objValue = oXMLDOMNode.nodeValue
objXMLDOMNode.nodeValue = objValue

Example

The following Microsoft® Visual Basic® example creates an IXMLDOMNode object and tests if it is a comment node. If it is, it displays its value.

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)
   If currNode.nodeTypeString = "comment" Then
      MsgBox currNode.nodeValue
   End If
End If
[C/C++]

C/C++ Syntax

HRESULT get_nodeValue(
    VARIANT *value);
HRESULT put_nodeValue(
    VARIANT value);

Parameters

value [out, retval][in]
Node value; depends on the nodeType property.

C/C++ Return Values

S_OK
Value returned if successful.
S_FALSE (for get_nodeValue only)
Value when returning Null.
E_INVALIDARG (for get_nodeValue only)
Value returned if the value parameter is Null.
E_FAIL (for get_nodeValue only)
Value returned if an error occurs.

Remarks

Variant. The property is read/write.

This value depends on the value of the nodeType property.

NODE_ATTRIBUTE Contains a string representing the value of the attribute. For attributes with subnodes, this is the concatenated text of all subnodes with entities expanded. Setting this value deletes all children of the node and replaces them with a single text node containing the value written.
NODE_CDATA_SECTION Contains a string representing the text stored in the CDATA section.
NODE_COMMENT Contains the content of the comment, exclusive of the comment's start and end sequence.
NODE_DOCUMENT

NODE_DOCUMENT_TYPE

NODE_DOCUMENT_FRAGMENT

NODE_ELEMENT

NODE_ENTITY

NODE_ENTITY_REFERENCE

NODE_NOTATION

Contains Null. Note that attempting to set the value of nodes of these types generates an error.
NODE_PROCESSING_INSTRUCTION Contains the content of the processing instruction, excluding the target. (The target appears in the nodeName property.)
NODE_TEXT Contains a string representing the text stored in the text node.

To view reference information for Visual Basic, C/C++, or Script only, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

nodeName Property | nodeType Property

Applies to: IXMLDOMAttribute | IXMLDOMCDATASection | IXMLDOMCharacterData | IXMLDOMComment | DOMDocument | IXMLDOMDocumentFragment | IXMLDOMDocumentType | IXMLDOMElement | IXMLDOMEntity | IXMLDOMEntityReference | IXMLDOMNode | IXMLDOMNotation | IXMLDOMProcessingInstruction | IXMLDOMText