Microsoft XML Core Services (MSXML) 4.0 - DOM Reference

setProperty Method

This method is used to set second-level properties on the DOM object.

[Script]

Script Syntax

objXMLDOMDocument2.setProperty(name, value);

Parameters

name
The name of the property to be set. For a list of properties that can be set using this method, see second-level properties.
value
The value of the specified property. For a list of property values that can be set using this method, see second-level properties.

Example

var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.4.0");
var selection;
xmlDoc.loadXML("<Customer><Name>Microsoft</Name></Customer>");
if (xmlDoc.parseError.errorCode <> 0) {
   var myErr = xmlDoc.parseError;
   alert("You have error " + myErr.reason);
} else {
   xmlDoc.setProperty("SelectionLanguage", "XPath");
   selection = xmlDoc.selectNodes("Customer/Name");
   alert(selection.expr + " -- " + selection.item(0).xml);
}

The preceding message box displays "Customer/Name -- <Name>Microsoft</Name>".

selection.expr = "/Customer";
alert(selection.expr + " -- " + selection.item(0).xml);

The preceding message box displays "/Customer –-<Customer><Name>Microsoft</Name></Customer>".

[Visual Basic]

Visual Basic Syntax

objXMLDOMDocument2.setProperty(name, value)

Parameters

name
The name of the property to be set. For a list of properties that can be set using this method, see second-level properties.
value
The value of the specified property. For a list of property values that can be set using this method, see second-level properties.

Example

Dim xmldoc As New Msxml2.DOMDocument40
Dim selection As Msxml2.IXMLDOMSelection

xmldoc.loadXML ("<Customer><Name>Microsoft</Name></Customer>")
If (xmlDoc.parseError.errorCode <> 0) Then
   Dim myErr
   Set myErr = xmlDoc.parseError
   MsgBox("You have error " & myErr.reason)
Else
   xmldoc.setProperty "SelectionLanguage", "XPath"
   Set selection = xmldoc.selectNodes("Customer/Name")
   MsgBox selection.expr + " -- " + selection.Item(0).xml
End If

The preceding message box displays "Customer/Name -- <Name>Microsoft</Name>".

selection.expr = "/Customer"
MsgBox selection.expr + " -- " + selection.Item(0).xml

The preceding message box displays "/Customer –-<Customer><Name>Microsoft</Name></Customer>".

[C/C++]

C/C++ Syntax

HRESULT setProperty (BSTR name, VARIANT value);

Parameters

name [in]
The name of the property to be set. For a list of properties that can be set using this method, see second-level properties.
value [in]
The value of the specified property. For a list of property values that can be set using this method, see second-level properties.

C/C++ Return Values

S_OK
Value returned if successful.
E_FAIL
Value returned if name or value is invalid.

Remarks

Examples of the second-level properties include SelectionLanguage, ServerHTTPRequest.

This method may not be applied to the first-level DOM properties that are exposed directly on a DOM object. Examples of the first-level properties include validateOnParse, async, parseError, etc.

See Also

selectSingleNode Method | selectNodes Method | second-level properties | getProperty Method

Applies to: IXMLDOMDocument2

This HTML Help has been published using the chm2web software.