GetNamedNodeProperty Method

Microsoft Office InfoPath

Returns the value of a named property for the specified XML node, which must be a nonattribute node in the main data source.

expression.GetNamedNodeProperty(ByVal varMainDOMNode As Variant, ByVal bstrPropertyName As String, ByVal bstrDefaultValue As String) As String

expression    Required. An expression that returns a reference to an XDocument object.

varMainDOMNode    Required Variant. An XML node corresponding to a nonattribute node in the main data source, for which a named property is to be set.

bstrPropertyName Required String. Specifies the name of the property whose value is to be returned.

bstrDefaultValue Required String. Specifies the default value to be returned if the property has not been set.

returns    A string corresponding to the current value of the named property for the specified XML node in the main data source. If the specified property has not been set for this XML node, the specified default string is returned.

Security Level

2: Can be accessed only by forms running in the same domain as the currently open form, or by forms that have been granted cross-domain permissions.

Remarks

Named properties allow users to associate strings with user-defined properties of XML element nodes in the main data source. The value of a named property can be set by using the SetNamedNodeProperty method. Use the GetNamedNodeProperty method to read the value of a named property.

Note  This object model member is not supported when the Disable Service Pack features option on the Advanced tab of the Options dialog box in InfoPath is selected or when Microsoft Office 2003 Service Pack 1 or later is not installed. Any form that implements this object model member in its code will generate an error message if it is opened in InfoPath when service pack features are disabled or unavailable.

Example

The following example demonstrates setting and getting the value of a named property (with the name "cost") of an XML node (called "item"):

var objXMLNode = XDocument.DOM.selectSingleNode("/items/item");

var strTest = XDocument.GetNamedNodeProperty(objXMLNode, 'cost', 'Value not set');

// The value of the "cost" named property is set to 100.
XDocument.SetNamedNodeProperty(objXMLNode, 'cost', '100');

strTest = XDocument.GetNamedNodeProperty(objXMLNode, 'cost', 'Value not set');

In the following XSL example, the "cost" named property of the item node is displayed:

<xsl:value-of select="xdXDocument:GetNamedNodeProperty(item, 'cost', 'empty')"/>