Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: XML::LibXML::Reader giving wrong matched element
by choroba (Cardinal) on Nov 24, 2011 at 14:45 UTC | |
|
Re: XML::LibXML::Reader giving wrong matched element
by ww (Archbishop) on Nov 24, 2011 at 14:59 UTC | |
by cavac (Prior) on Nov 24, 2011 at 23:41 UTC | |
by ww (Archbishop) on Nov 25, 2011 at 01:50 UTC | |
by ikegami (Patriarch) on Nov 25, 2011 at 02:11 UTC | |
by ww (Archbishop) on Nov 25, 2011 at 04:04 UTC | |
| |
|
Re: XML::LibXML::Reader giving wrong matched element
by locked_user sundialsvc4 (Abbot) on Nov 24, 2011 at 14:20 UTC |