Microsoft KB Archive/285163

= PRB: XPath Query Returns Unexpected Data =

Article ID: 285163

Article Last Modified on 10/12/2001

-

APPLIES TO


 * Microsoft XML Parser 2.0
 * Microsoft XML Parser 2.5
 * Microsoft XML Parser 2.6
 * Microsoft XML Core Services 4.0
 * Microsoft XML Core Services 4.0

-



This article was previously published under Q285163



SYMPTOMS
When you execute an XPath query similar to either of the following, the expected data may not be returned: book/title[0] book/title[1] The first query is actually querying for the set of the first title nodes for each book node. The second query is also querying the set of all the second title nodes for each book node. In order to find instances of title nodes that occur under a specified book node, the queries should be as follows: (book/title)[0] (book/title)[1] This is because of operator precedence, which, by default, associates the index qualifier with the title rather than the book/title path. The use of parentheses forces the index qualifier to be associated with all book/title nodes.



RESOLUTION
To resolve problems such as this with XPath queries, verify the syntax of the XPath query and ensure that operator precedence is observed.



STATUS
This behavior is by design.



Steps to Reproduce Behavior
  Insert the following code into a new document:    function RunQuery(strQuery) {           var ResultNodes, Node, savedNodeString = String(&quot;&quot;); ResultNodes = XMLData.documentElement.selectNodes(strQuery);

for (Node = ResultNodes.nextNode; Node != null; Node = ResultNodes.nextNode) {               savedNodeString+=Node.xml; }           ResultsDiv.innerText = savedNodeString; return; }        <BR><BR> <CENTER><B>Results:</B></CENTER><BR> <HR WIDTH=&quot;80%&quot; NOSHADE> <DIV ID=&quot;ResultsDiv&quot; style=&quot;border-color:black;border-width:1;border-style:solid;width:100%;height:100;&quot;> </DIV> <BR> <CENTER><B>Source Data:</B></CENTER><BR> <HR WIDTH=&quot;80%&quot; NOSHADE> <DIV ID=&quot;DataDiv&quot; style=&quot;border-color:black;border-width:1;border-style:solid;width:100%;height:100;&quot;> </DIV>

<XML ID=&quot;XMLData&quot;> <?xml version=&quot;1.0&quot; ?> <book style=&quot;biography&quot;> Adam Barr: International Man of Mystery John Coake 12            <book style=&quot;textbook&quot;> A Nanotechnology Primer Josh Barnhill 55            <book style=&quot;storybook&quot;> XQL: The Golden Years 30    </XML> </BODY> </HTML> </li> <li>Save the document as Sample.htm, and then browse to it by using an Internet Explorer (IE) Web browser, version 5.0 or greater. Click the buttons at the top of the page, and note that the first two queries (in which there are no parentheses) return the first and second titles of each book. Because there are no second titles, the second query returns nothing. The last two queries (with parentheses) return the first book title and the second book title respectively.</li></ol>

Keywords: kbprb KB285163

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.