value Property

MSXML 5.0 SDK

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

value Property

Contains the attribute value.

[Script]

Script Syntax

objValue = oXMLDOMAttribute.value;
objXMLDOMAttribute.value = objValue;

Example

The following script example gets the value of the first attribute of the document root and assigns it to the variable myVar.

var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.5.0");
var myVar;
xmlDoc.async = false;
xmlDoc.load("books.xml");
if (xmlDoc.parseError.errorCode != 0) {
   var myErr = xmlDoc.parseError;
   alert("You have error " + myErr.reason);
} else {
   root = xmlDoc.documentElement;
   myVar = root.firstChild.attributes.item(0).value;
   alert(myVar);
}
[Visual Basic]

Visual Basic Syntax

objValue = oXMLDOMAttribute.value
objXMLDOMAttribute.value = objValue

Example

The following Microsoft® Visual Basic® example gets the value of the first attribute of the document root and assigns it to the variable myVar.

Dim xmlDoc As New Msxml2.DOMDocument50
Dim myVar As Variant
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 root = xmlDoc.documentElement
   myVar = root.firstChild.Attributes.Item(0).Value
   MsgBox myVar
End If
[C/C++]

C/C++ Syntax

HRESULT get_value(
    VARIANT *attributeValue);
HRESULT put_value(
    VARIANT *attributeValue);

Parameters

attributeValue [out, retval][in]
The value of the attribute. For attributes with subnodes, the string is the concatenated text of all subnodes with character and general entity reference expanded (replaced with their values).

C/C++ Return Values

S_OK
The value returned if successful.
E_INVALIDARG (for get_value only)
The value returned if the attributeValue parameter is Null.
E_FAIL (for put_value only)
The value returned if an error occurs.

Remarks

Variant. The property is read/write. It returns the value of the attribute. For attributes with subnodes, the string is the concatenated text of all subnodes with character and general entity references expanded (replaced with their values).

The new attribute value is added as the value of a single text node that is a child of the attribute node. The string contents are unparsed.

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

Applies to: IXMLDOMAttribute