Eythil has asked for the wisdom of the Perl Monks concerning the following question:
<result> <target type="aim"> <tag1>123</tag1> <tag2>456</tag2> ... </target> </result>
I want to match the 'tag'-tags with a regex or a nice xpath expression, but I fail doing so (maybe it is because I am a perl beginner).
So far I tried with regular expressions like:and xpathes like:my $twig = new XML::Twig(twig_handlers => { "/result/target/tag[1-3]" => \&my_parsing_function, });
Unfortunately both won't work.my $twig = new XML::Twig(twig_handlers => { "/result/target/tag[self::1 or self::2 or self::3]" => \&my_parsing_ +function });
The Twig documentation mentions it supports 'xpath-like' expression, but it seems I am doing it the wrong way.
Is there a way to do the matching with twig or is it better to match the parent tag and do the matching afterwards?
(I hope my english is understandable enough to get an impression of what I want to do)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: XML::Twig and handles on regex/xpath
by Corion (Patriarch) on Apr 28, 2011 at 08:05 UTC | |
by Eythil (Acolyte) on Apr 28, 2011 at 08:17 UTC | |
by Corion (Patriarch) on Apr 28, 2011 at 08:22 UTC | |
by Eythil (Acolyte) on Apr 28, 2011 at 08:33 UTC | |
by Anonymous Monk on Apr 28, 2011 at 08:49 UTC | |
| |
|
Re: XML::Twig and handles on regex/xpath
by wind (Priest) on Apr 28, 2011 at 08:06 UTC | |
by Eythil (Acolyte) on Apr 28, 2011 at 08:13 UTC | |
by wind (Priest) on Apr 28, 2011 at 08:20 UTC | |
by Eythil (Acolyte) on Apr 28, 2011 at 08:25 UTC | |
|
Re: XML::Twig and handles on regex/xpath
by mirod (Canon) on Apr 28, 2011 at 09:13 UTC | |
|
Re: XML::Twig and handles on regex/xpath
by dHarry (Abbot) on Apr 28, 2011 at 11:14 UTC | |
by Eythil (Acolyte) on Apr 28, 2011 at 11:27 UTC |