Previously I had been using XPATH and it worked a treat...but the parsing was just too slow. After writing to the author (Matt Seargent) he suggested that I use LibXML as in his words it was "much much faster"
However..my XPATH expressions no longer seemed to work. I solved part of this problem by declaring a namespace but have been unable to craft the XPATH expression needed to get the text I am after.
I have simplified the problem below maintaining all the important structural elements and am hoping someone might be able to throw me a bone as to what I am doing wrong.
Example XML and the source code I am using is below
I would appreciate any thoughts at this stage as myself and Mr Google have come up empty handed.
Regards
Steddy.
=========================== <?xml version="1.0" encoding="UTF-8"?> <RootTag SchemaVersion="1.1" xmlns="http://www.wow.com/BlahML" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocati +on="http://www.wow.com/BlahML BlahML1_1.xsd"> <MyTagA Tag="XXX">Some Text A</MyTagA> <MyTagB Tag="XXX">Some Text A</MyTagB> <MiddleTag xsi:type="foo" magicvalue="wow"> <MyImportantNode> xsi:type="foo" GeneralID="Random1" > <CannotGetTagA> YYYYYYYYYYY </CannotGetTagA> <CannotGetTagB> ZZZZZZZZZZZ </CannotGetTagB> </MyImportantNode> <MyImportantNode> xsi:type="foo" GeneralID="Random2" > <CannotGetTagA> YYYYYYYYYY22 </CannotGetTagA> <CannotGetTagB> ZZZZZZZZZZ22 </CannotGetTagB> </MyImportantNode> <MyImportantNode> xsi:type="foo" GeneralID="Random3" > <CannotGetTagA> YYYYYYYYY333 </CannotGetTagA> <CannotGetTagB> ZZZZZZZZZ333 </CannotGetTagB> </MyImportantNode> </MiddleTag> </RootTag> =========================== use strict; use XML::LibXML; my $version = "v0.1 - Dances with XML"; my $parser = XML::LibXML->new(); $parser->recover_silently(1); my $doc = $parser->parse_file('test.xml'); #<-- The above XML my $xpc = XML::LibXML::XPathContext->new($doc); $xpc->registerNs(theNS => 'http://www.wow.com/BlahML'); my @MiddleNodeBits = $xpc->findnodes('//theNS:MiddleTag'); foreach my $nodeybits (@MiddleNodeBits) { # [1] Works but only gives me "Random1". Expected Random1,2 and 3 print $nodeybits->findnodes('//@GeneralID')->string_value . "\n"; # [2] Works...but gives me the entire XML once. Not very useful. print $nodeybits->findnodes('//*')->string_value . "\n"; ############################################## # No output from lines below-Not sure why? ############################################## # [3] print $nodeybits->findnodes('//CannotGetTagA')->string_value . "\ +n"; # [4] print $nodeybits->findnodes('/RootTag/MiddleTag[1]/MyImportantNod +e[1]/CannotGetTagA[1]/text()')->string_value . "\n"; # [5] print $nodeybits->findnodes('theNS:RootTag/MiddleTag[1]/MyImportan +tNode[1]/CannotGetTagA[1]/text()')->string_value . "\n"; # [6] print $nodeybits->findnodes('//RootTag/MiddleTag[1]/MyImportantNod +e/CannotGetTagA/text()')->string_value . "\n"; } exit(0);
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |