pp108 : selectXMLNode()

selectXMLNode()


It searches for the XML node that matches the specified XPath expression and returns the first XML node that meets the criteria.

Syntax

Script cordys.selectXMLNode(XMLNode, xpathExpression, [namespaces])


Parameters

Parameter Description
XMLNode Refer to the xmlNode or xmlDocument to search in.
xpathExpression Refers to the XPath expression that is set as the search criteria.
namespaces Optional. Refers to the namespace that is set in the search criteria. The value that you provide for this parameter must be an array of prefixes and namespaces; for example,{ "ns1": "namespace1", "ns2": "namespace2" }.


Return Value


A single node in the XML document.

Remarks


XPath expressions can include namespaces. Namespace resolution is supported using thecordys.setXMLNamespaces()method or using the specified namespace argument of selectXMLNode. If selectXMLNode is called inside a loop, it helps improve performance if the namespaces are first set ascordys.setXMLNamespacesand then used in the loop. Providing namespaces for selectXMLNode in each loop affects the performance.

If the XPath expression does not include a prefix, the empty namespace is considered as the namespace URI. If your XML includes a default namespace, ensure that you add a prefix and namespace URI, or no nodes will be selected.

Example
cordys.setXMLNamespaces(xmlNode, { "ns1":"namespace1" }  );
var nodeList = cordys.selectXMLNodes(xmlNode, "ns1:myxpath")
for ( var i=0, length=nodeList.length; i < length; i++ )
{
	var propertyNode = cordys.selectXMLNode(nodeList[i],  "ns1:mypropertyxpath");
	var nodeText = cordys.getTextContent(propertyNode);
	var nodeXML = cordys.getXML(propertyNode);
}

Applies to


cordys