and here is the code<world> <country short="usa" name="united state of america"> <state short="CA" name="california"/> <city short="SFO" name="San Franscisco"/> <city short="EM" name="Emeryville"/> <state short="FL" name="florida"/> <city .../> . <city ../> </country> <country short="abc" name="a for apple"> <state ..../> </country> </world>
use XML::LibXML::Reader; my $reader = XML::LibXML::Reader->new(location => "map.xml"); my $pattern = XML::LibXML::Pattern->new('/world'); my @matchedNodes; while ($reader->nextPatternMatch($pattern)) { push @matchedNodes, $reader->copyCurrentNode(1); }
@matchedNodes give me two elements. why? There is only one world tag. What is wrong with my code?
similarly when I use the pattern my $pattern = XML::LibXML::Pattern->new('/world/country');
It give me four elements whereas I am having only two country tags.
Please explain me where am I doing wrong? I need to use Pattern (for xPath) and I can not avoid it. Also, I would like to stick with XML::LibXML::Reader for some comtability reasons.
Please help.In reply to XML::LibXML::Reader giving wrong matched element by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |