falcong / pugixml

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

XPATH without exceptions #62

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. define NO_EXCEPTIONS
2. use any xpath functionality

What is the expected output? What do you see instead?
error while compiling. This is expected due the documented define NO_EXCEPTIONS

What version of the product are you using? On what operating system?
0.6 / windows xp / vc9

Please provide any additional information below.
Due exceptions may not be catched a return macro in case NO_EXCEPTIONS is
defined would do the job quite perfect. then the user just needs to check
pugi::xpath_node.empty() for example. Maybe a error code or something in
pugi::xpath_node would be the whipped cream in the NO_EXCEPTIONS coffe.

btw.. i love pugi!

Original issue reported on code.google.com by flying.l...@gmail.com on 27 May 2010 at 2:23

GoogleCodeExporter commented 9 years ago
Thanks for the feature request. The support of XPath without exceptions is in 
my todo 
list. It's likely to make it into the next major release (which I expect to do 
in a 
month or so). I'll update this issue once there is something to report.

Original comment by arseny.k...@gmail.com on 27 May 2010 at 4:14

GoogleCodeExporter commented 9 years ago
Hello, I'm really interested in such enhancement in the main source tree. Some 
month ago (v 0.5), I had to do it for our project (using macros) and I just 
finished to redo it for 0.9

Here is the diff patch file

In short, all method which return node* now return NULL instead of exception if 
PUGIXML_NO_EXCEPTIONS is set
xpath_lexer::next() assert false

I haven't tested a lot, only compile with/without PUGIXML_NO_EXCEPTIONS and run 
a very basic test using pugixml but I don't think I have broke something

Original comment by renaud.g...@gmail.com on 20 Jul 2010 at 8:34

Attachments:

GoogleCodeExporter commented 9 years ago

Original comment by arseny.k...@gmail.com on 21 Jul 2010 at 7:21

GoogleCodeExporter commented 9 years ago
I'm increasing the issue priority - XPath without exceptions will definitely be 
available in the next version. It may be available in the trunk soon, no 
promises though.

Your patch is not ideal - it should work as long as all XPath queries are 
valid, but otherwise you will experience invalid query results or even null 
pointer dereferences. I am going to take a slightly different approach - the 
internals of query compilation will not use exceptions at all, and the root 
function (compile()) will get the compilation result - with error message and 
error location - and either throw it in an exception object or store in query.

select_nodes and select_single_node will return empty node set and empty node, 
respectively, if the query compilation failed or if the return type is not node 
set.

Original comment by arseny.k...@gmail.com on 21 Jul 2010 at 7:29

GoogleCodeExporter commented 9 years ago
I agree it's a trivial patch to rapidly solve my problem (compile with 
-fno-exception). As you say, I assume my queries are valid and never fall in 
the exception case :)

Original comment by renaud.g...@gmail.com on 23 Jul 2010 at 4:59

GoogleCodeExporter commented 9 years ago
XPath implementation was considerably redesigned; as a result, it can now work 
without exceptions, without STL or without both.

Using PUGIXML_NO_EXCEPTIONS now changes the XPath error handling mechanism: no 
exceptions are ever thrown, all evaluate and select* calls return the default 
value for incorrect queries, and you can check if the query compiled fine using 
xpath_query as a boolean object (i.e. if (query)) or by calling result() method 
and inspecting the error message/offset.

You can grab the updated source from trunk (note that there is no pugixpath.cpp 
any more - just remove it from your project), or you can wait for the next 
release (which is expected in November).

Original comment by arseny.k...@gmail.com on 20 Sep 2010 at 7:16

GoogleCodeExporter commented 9 years ago
pugixml-1.0 is out; it no longer requires exceptions to work, as noted above - 
the error handling mechanism depends on whether PUGIXML_NO_EXCEPTIONS is on. 
The documentation has additional details.

Original comment by arseny.k...@gmail.com on 31 Oct 2010 at 6:20