Skip Menu |

This queue is for tickets about the XML-DOM-XPath CPAN distribution.

Report information
The Basics
Id: 8977
Status: resolved
Priority: 0/
Queue: XML-DOM-XPath

People
Owner: MIROD [...] cpan.org
Requestors: ben.hsing [...] oracle.com
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 0.06
Fixed in: 0.07



Subject: XML::DOM::XPath methods do not work on objects created by XML::DOM::Document->new
Hey Michel sorry it's me again (ouch). :-P The following simple piece of code does not work: -- CODE BEGINS -- use XML::DOM::XPath; $xml = new XML::DOM::Document; $root = $xml->createElement('root'); $xml->appendChild($root); print "hello world" if $xml->exists('root'); -- CODE ENDS -- This will produce the following error message: Can't call method "exists" on an undefined value at /usr/local/perl561/lib/site_perl/5.6.1/XML/DOM/XPath.pm line 57. But the same method call on the same XML structure generated by XML::DOM::Parser works flawlessly: -- CODE BEGINS -- use XML::DOM::XPath; $xml = new XML::DOM::Parser->parse('<root/>'); print "hello world" if $xml->exists('root'); -- CODE ENDS -- This will print the string "hello world" as intended. The workaround for me right now is to convert the DOM object back to XML first and then let the parser parse into a DOM object again just for XPath query purposes: -- CODE BEGINS -- use XML::DOM::XPath; $xml = new XML::DOM::Document; $root = $xml->createElement('root'); $xml->appendChild($root); print "hello world" if XML::DOM::Parser->new->parse($xml->toString)->exists('root'); -- CODE ENDS -- And this is obviously crude and inefficient (but works). Again, I'm running Perl 5.6.1 built for i686-linux, with XML-DOM-1.43, XML-XPath-1.13 and XML-DOM-XPath-0.06 installed. Thanks a lot, Michel!
OK, It's fixed on the development version on my web site ( http://www.xmltwig.com/module/xml-dom-xpath/) Let me know if it works for you. BTW, the syntax 'new XML::DOM::Document' is deprecated, it is safer to use XML::DOM::Document->new __ Mirod
Hi, Michel, Cool. I see your clever replacement of the parser constructors with just a Document constructor. The fix looks totally good to me. :-) Thanks again, Ben
Show quoted text
> BTW, the syntax 'new XML::DOM::Document' is deprecated, it is safer to > use XML::DOM::Document->new
I see. Thanks for pointing that out. Thanks, Ben