Click here to get back home

LibXML "Undefined namespace prefix"

 HomeNewsGroups | Search | About
 comp.lang.perl.modules    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
LibXML "Undefined namespace prefix" Andrew 07-02-2007
Posted by Steven Hirsch on July 11, 2007, 7:57 am
Please log in for more thread options


Andrew wrote:
> I am using LibXML to parse an XML file. The XML file is like so...
>
> | <MyApp:Config>
> | <MyApp:FilterMgr>
> | ...
> | </MyApp:FilterMgr>
> | <MyApp:DBConnMgr>
> | <RecalcMgr:RecalcMgr>
> | ...
> | </RecalcMgr:RecalcMgr>
> | </MyApp:DBConnMgr>
> | </MyApp:Config>
>
> Here is the relevant code...
>
> | use XML::LibXML;
> | ...
> | my $config = XML::LibXML->new->parse_file('config.xml');
> | my $xpc = XML::LibXML::XPathContext->new($config);
> | my @nodes = $xpc->findnodes($theXPath);
>
> If $theXPath contains any prefix other than MyApp (like DBConnMgr),
> then I get the following error...
>
> | Undefined namespace prefix
> | xmlXPathCompiledEval: evaluation failed
>
> Is there some limitation/bug when it comes to namespace prefixes
> nested within other namespace prefixes? I know that the namespaces
> are all defined in one DTD. And everything was fine when this code
> used XML::Parser instead of XML::LibXML...

I think I've run into the same thing. Found this comment in some old code
that uses LibXML:

# For reasons beyond my ken, XPath expressions involving
# internally-defined namespaces fail with 'undefined prefix'
# errors unless we place a dummy attribute at the root
# element. Don't even ask how many hours I spent chasing
# this.
my $attr = $dom->createAttributeNS( '', 'dummy', '' );
$dom->getDocumentElement()->setAttributeNodeNS( $attr );

May be worth a try?

Steve

Similar ThreadsPosted
Help! SOAP::Lite: How to set the namespace prefix for the request? June 18, 2006, 2:54 pm
namespace declarations in LibXML April 15, 2006, 12:48 am
"Undefined subroutine" November 21, 2004, 8:48 pm
Getting "undefined sysmbol February 8, 2005, 8:12 am
GD-1.38: Undefined symbol: .__fixsfsi July 12, 2004, 10:43 am
undefined symbol: gdImageCreateFromGif June 14, 2007, 1:00 pm
SOAP::Lite " December 1, 2006, 5:13 am
Mail::IMAPClient folders($prefix) March 24, 2007, 10:18 pm
HTTP::Response decoded_content is undefined March 28, 2007, 8:04 am
Can't call method on an undefined value at June 27, 2005, 2:56 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap