letanphuc / pugixml

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

select_single_node returning empty node on failure considered bad. #200

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
Call select_single_node() on a path that is not found. You get xpath_node() 
returned.. but how to distinguish this from a validly "found" node?

What is the expected output? What do you see instead?
I would have hoped to see a "valid()" call, where xpath_node() {vaiid=false;} 
and other constructors set valid=true; -- or something of that sort. There are 
of course many ways of doing this. Perhaps an "error" state or something else 
in xpath_node(). Maybe even in xml_node too?

Which version of pugixml are you using? On what operating system/compiler?
1.2 tarball. Windows VS

Please provide any additional information below.

Original issue reported on code.google.com by rivimeyc...@gmail.com on 3 Mar 2013 at 1:52

GoogleCodeExporter commented 9 years ago
if (node)
or
if (!node)
works.

See 
http://pugixml.googlecode.com/svn/tags/latest/docs/manual/xpath.html#xpath_node:
:unspecified_bool_type

Original comment by arseny.k...@gmail.com on 3 Mar 2013 at 3:00

GoogleCodeExporter commented 9 years ago
Clarification from the point of view of API design: empty handles are used 
throughout pugixml to designate 'not found' or erroneous state. Since the only 
case when select_single_node can return an empty xpath_node is when the query 
does not result in any nodes, I don't see any ambiguity here.

Original comment by arseny.k...@gmail.com on 3 Mar 2013 at 3:07

GoogleCodeExporter commented 9 years ago
Arseny, thanks for your comment.

When you say "if (node)" the "node" is the return value from the call? i.e. an 
xpath_node?

It would be good to include this in the docs explicitly.. perhaps you could 
consider this issue a docs defect?

Original comment by rivimeyc...@gmail.com on 3 Mar 2013 at 10:08

GoogleCodeExporter commented 9 years ago
Yes, it's an xpath_node object. I'll clarify the way to check the return value 
in documentation.

Original comment by arseny.k...@gmail.com on 6 Mar 2013 at 4:04

GoogleCodeExporter commented 9 years ago
Documentation has been slightly updated in trunk with this issue in mind; 
expect a new documentation in the new version, which should be released soon.

Original comment by arseny.k...@gmail.com on 10 Jul 2013 at 4:48