falcong / pugixml

Automatically exported from code.google.com/p/pugixml
0 stars 0 forks source link

xpath issue: "\\" syntax #111

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
load xml file, and query nodes using xpath.

What is the expected output? What do you see instead?
I expect "pugi::xpath_node_set keywords = 
node.select_nodes("//keywords/keyword");" can output all "keyword" node UNDER 
the current node. However, the program output all "keyword" node in the 
document.

Which version of pugixml are you using? On what operating system/compiler?
I'm using pugixml-1.0, microsoft vc 2010.

Please provide any additional information below.
according to w3c, "//" means "//    Selects nodes in the document from the 
current node that match the selection no matter where they are 
"(http://www.w3schools.com/xpath/xpath_syntax.asp)

Original issue reported on code.google.com by xinlin...@gmail.com on 4 Jul 2011 at 6:38

Attachments:

GoogleCodeExporter commented 9 years ago
Your understanding is incorrect.
Quoting XML XPath recommendation examples, section 2.5 Abbreviated Syntax:

//para selects all the para descendants of the document root and thus selects 
all para elements in the same document as the context node

.//para selects the para element descendants of the context node

In this case, context node is the one you're using select_nodes on, so your 
query should scan the entire document.

"Current" node from w3schools likely means the case when // is used in the 
middle of a path, i.e. keyword[@name='get']//item. In this query only item 
descendants of the get keyword will be found; the case where the XPath query 
begins with // is special in XPath grammar.

You can change the query to ".//keywords/keyword" to get the expected results.

Original comment by arseny.k...@gmail.com on 4 Jul 2011 at 6:47

GoogleCodeExporter commented 9 years ago
thank you very much! It's my fault~~

Original comment by xinlin...@gmail.com on 4 Jul 2011 at 7:11