I have XML similiar to this:
<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:
my $twig = new XML::Twig(twig_handlers =>
{
"/result/target/tag[1-3]" => \&my_parsing_function,
});
and xpathes like:
my $twig = new XML::Twig(twig_handlers =>
{
"/result/target/tag[self::1 or self::2 or self::3]" => \&my_parsing_
+function
});
Unfortunately both won't work.
The regex version just ignores the tags,
the xpath one fails, because of 'unrecongnised expression in handler'.
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?
Thank you!
(I hope my english is understandable enough to get an impression of what I want to do)
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.