Error handling the appendXML method of the built in DOMDocumentFragment class

Skip to first unread message

Ryan Mahoney

Apr 12, 2009, 2:16:29 PM4/12/09
to devel-querypath
The "prepareInsert" method of the class "QueryPathImpl" has the
following lines:

$frag = $this->document->createDocumentFragment();

A problem with this code, is that under a variety of fairly common
scenarios the appendXML method will return FALSE. Currently, this
case is not handled, so when it happens there is a silent failure.
I've tried adding in some error handling, you can easily test if the
return value is false, but I can not seem to access any error
message. I even tried using "libxml_get_errors" but that did not work
either. I know that there is a DOMException class, but it doesn't
seem like any exception is being thrown.

Any ideas?


Ryan Mahoney

Apr 12, 2009, 2:34:49 PM4/12/09
to devel-querypath
After further investigation, domdocumentfragment.appendxml issues a
bunch of PHP warnings when it fails.


Matt Butcher

Apr 12, 2009, 6:16:21 PM4/12/09
to devel-querypath
I will take a look at this tomorrow (Monday). At first blush, this
certainly seems like a buggy way for QueryPath to (not) handle errors.
I'll see what I can do to fix it.

Matt Butcher

Apr 13, 2009, 12:20:41 PM4/13/09
to devel-querypath
I took a closer look at this today.

If I pass something invalid into a method that calls prepareInsert(),
I get PHP warnings from the DOM parser. Execution is not interrupted,
though. QueryPath will continue to function, though the data will not
be added to the document.

I believe this is the desired behavior. I'm not wild about generating
a fatal error, and while I could throw an exception under such
conditions, I'm concerned that that will cause frustration with
QueryPath developers who aren't used to try/catch blocks (since a
failure to catch will lead to a fatal).

I'm open to input, though. If you have a suggestion for better overall
error handling, please let me know. I come from the Java world, where
exceptions are the way to go. But most PHP code that I have seen seems
to blissfully ignore exceptions. I just want my library to be easy to
use for the majority of PHP developers.

Thanks for taking the time to hunt down the issue.

Reply all
Reply to author
0 new messages