|
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
|