|
Posted by Andrew on July 5, 2007, 1:15 pm
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...
>
> >>Thanks in advance for any suggestions.
>
> > I have found a temporary solution. Except for the namespace prefix
> > that works ("MyApp" in the example above), I removed all other
> > prefixes from the XPath. (Of course, optionally, I could remove the
> > working prefix as well.)
>
> > It's still not clear to me why this happened, so any suggestions are
> > still welcome. Thanks!
>
> http://www.perlmonks.org/?node_id=555011might be relevant
>
> The last time I used XML::LibXML to parse some received XML I found it
> easiest to just perform a namespacectomy on the XML first :-)
>
> Elsewhere I've read that you can use XPaths like
> "//*[name()='prefix:ElementName']"
Thanks for the response. Unfortunately, I've seen these suggestions
while searching Google myself, and I haven't been able to solve my
issue. I also take back the temporary "solution" that I posted --
that didn't work either, I found out. (It just got rid of the error
message.)
It works when I register namespaces using registerNs(<prefix>, <uri/
url>). However, I have to manually registerNs every prefix...
|