in reply to XML::Twig and handles on regex/xpath

When debugging XPath expressions, I usually work my way up from the "deepest" tag I want to match. In your case, I'd first try to match things with a tagName matching /^tag\d+$/:

//*[starts-with(name(), "tag")]

Then, I'd slowly work my way upwards, adding more specific tags or rules in front of it:

//target/*[starts-with(name(), "tag")] //result/target/*[starts-with(name(), "tag")]

Ideally, at the end, I can then remove the floating specifier:

/result/target/*[starts-with(name(), "tag")]

Maybe you need to change your expression, or maybe XML::Twig doesn't support the starts-with() function - then I'd try the direct regular expression approach. I really wonder though whether your usage of specifying regular expressions instead of XPath expressions is correct, as I wuold imagine that XML::Twig interprets your first expression as XPath expression as well. I'm not sure how self::1 is supposed to work in conjunction with tag, as I don't think that tag[EXPR] will ever match anything that doesn't have an explicit tagName of "tag".

Replies are listed 'Best First'.
Re^2: XML::Twig and handles on regex/xpath
by Eythil (Acolyte) on Apr 28, 2011 at 08:17 UTC
    Thanks.
    Sadly, this also gives an 'unrecogniced expression' error.
    I assume Twig does not support this kind of xpath expression.

      What gives an "unrecogniced expression" error?

      I posted three different XPath expressions. You have shown neither the Perl code you use, nor the input data you use nor the XPath expression you use, nor the error message you use. Please help us to help you better by providing us with the relevant information.

      Looking at the XML::Twig documentation, it recommends looking at XML::Twig::XPath for more XPath support.

        Actually I get the error message as soon as I try use the '[starts-with(...)]'.

        Thanks for pointing out XML::Twig::XPath.
        I will try to come up with a solution using this and post it here.