You are here: Reference > JavaScript > client-side > xml handling > properties > resultType (XPathResult)

resultType property (XPathResult)

Browser support:
Retrieves the type of the result represented by the 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 of the method. For detailed information, see the page for the evaluate method.

Syntax:

object.resultType;
You can find the related objects in the Supported by objects section below.
This property is read-only.

Possible values:

Integer that represents the type of the result. Predefined constants are available for the possible values of this property, in the scope of the XPathResult object. For further details, see the page for the XPathResult object.
The value can be one of the following values (the value of a predefined constant appears in parentheses after the constant):
NUMBER_TYPE (1)
The result is a number. Use the numberValue property to get the value of the result.
STRING_TYPE (2)
The result is a string. Use the stringValue property to get the value of the result.
Boolean_TYPE (3)
The result is a Boolean. Use the booleanValue property to get the value of the result.
UNORDERED_NODE_ITERATOR_TYPE (4)
The result contains all nodes that match the expression, but not necessarily in the same order as they appear in the document hierarchy. Use the iterateNext method to get the matching nodes.
ORDERED_NODE_ITERATOR_TYPE (5)
The result contains all nodes that match the expression, in the same order as they appear in the document hierarchy. Use the iterateNext method to get the matching nodes.
UNORDERED_NODE_SNAPSHOT_TYPE (6)
The result contains snapshots for all nodes that match the expression, but not necessarily in the same order as they appear in the document hierarchy. Use the snapshotItem method to get the matching nodes.
ORDERED_NODE_SNAPSHOT_TYPE (7)
The result contains snapshots for all nodes that match the expression, in the same order as they appear in the document hierarchy. Use the snapshotItem method to get the matching nodes.
ANY_UNORDERED_NODE_TYPE (8)
The result is a node that matches the expression. The result node is not necessarily the first matching node in the document hierarchy. Use the singleNodeValue property to get the matching node.
FIRST_ORDERED_NODE_TYPE (9)
The result is the first node in the document hierarchy that matches the expression. Use the singleNodeValue property to get the matching node.
Default: this property has no default value.

Example HTML code 1:

This example illustrates the use of the resultType property:
<head>
    <script type="text/javascript">
        function CountofButtons () {
            if (document.evaluate) {    // Firefox, Opera, Google Chrome and Safari
                var xPathRes = document.evaluate ('count(//BUTTON)', document, null, XPathResult.ANY_TYPE, null);
                if (xPathRes.resultType == XPathResult.NUMBER_TYPE) {
                    alert ('This document contains ' + xPathRes.numberValue + ' button element(s)');
                }
                else {
                    alert ("The evaluate method has a bug, the type of the result must be number!");
                }
            }
            else {  // Internet Explorer
                alert ("Your browser does not support the evaluate method!");
            }
        }
    </script>
</head>
<body>
    <button onclick="CountofButtons ()">Get the number of buttons!</button>
</body>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content