You are here: Reference > JavaScript > client-side > xml handling > properties > singleNodeValue (XPathResult)
singleNodeValue property (XPathResult)
Returns the single node represented by the current XPathResult object.
The XPathResult object represents the result of the evaluate method.
The type of the result depends on the fourth parameter of the evaluate method, or, if its value is ANY_TYPE, on the expression specified by the first parameter.
With the resultType property, the type of the result can be retrieved.
If the value of the resultType property is ANY_UNORDERED_NODE_TYPE or FIRST_ORDERED_NODE_TYPE,
then the singleNodeValue property retrieves the result node, else the use of the singleNodeValue property raises an exception.
Syntax:
You can find the related objects in the Supported by objects section below.
This property is read-only.
Possible values:
Returns the node represented by the current XPathResult object, or null if no matching node found.
Default: this property has no default value.
Example HTML code 1:
This example illustrates the use of the singleNodeValue property:
|
||||
<head> <script type="text/javascript"> function GetFirstButton () { if (document.evaluate) { // Firefox, Opera, Google Chrome and Safari var xPathRes = document.evaluate ('//BUTTON', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null); if (xPathRes.singleNodeValue) { alert ('The label of the first button: ' + xPathRes.singleNodeValue.textContent); } else { alert ("No button found!"); } } else { // Internet Explorer alert ("Your browser does not support the evaluate method!"); } } </script> </head> <body> <button onclick="GetFirstButton ()">Get the first button in the document!</button> </body> |
||||
|
||||
Did you find this example helpful?
|
Supported by objects:
Related pages:
XPathResult
createNodeIterator
evaluate
booleanValue
invalidIteratorState
numberValue
resultType
snapshotLength
stringValue
createNodeIterator
evaluate
booleanValue
invalidIteratorState
numberValue
resultType
snapshotLength
stringValue
External links:
User Contributed Comments