Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

xml::Twig partial_path question

by anniyan (Monk)
on Nov 23, 2005 at 14:04 UTC ( #511090=perlquestion: print w/ replies, xml ) Need Help??
anniyan has asked for the wisdom of the Perl Monks concerning the following question:

Monks, in twig_handlers i am using a path $epath as shown below to change the 'title' tag into 'tit'.

In order to access the 'title' tag i am giving such long path, i know we can give just 'title' alone to access via partial_path. But i want to know whether we can give something like 'gutbook/*/title' means gutbook followed by any elements and finally title, else is there anyother way to ignore the element names inbetween.

$epath = 'gutbook/book/frontmatter/titlepage/title'; my $twig = XML::Twig->new( twig_handleres => { '$epath' => \&normal} ); $twig->parse(\*DATA); __DATA__ <gutbook> <book> <frontmatter> <titlepage> <title>THE ILIAD</title> <author>HOMER</author> </titlepage> </frontmatter> <bookbody> <chapter> <title>BOOK I</title> <para> Sing, O goddess, the anger of Achilles son of Peleus, that brought countless ills upon the Achaeans. </para> </chapter> </bookbody> </book> </gutbook>

Regards,
Anniyan
(CREATED in HELL by DEVIL to s|EVILS|GOODS|g in WORLD)

Comment on xml::Twig partial_path question
Download Code
Re: xml::Twig partial_path question
by Tanktalus (Canon) on Nov 23, 2005 at 18:38 UTC

    Two things. First, your question: according to XPath, that would be 'gutbook//title' - this will match any 'title' element that is a child of a 'gutbook' to any depth.

    Second, I don't think '$epath' is doing what you think it's doing. This is a good reason to never quote variables unless you need to. The single quotes do not do interpolation, so that you end up literally with the characters '$', 'e', 'p', 'a', 't', and 'h' making up the string. Just remove the quotes and it'll do what you want.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://511090]
Approved by Limbic~Region
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (8)
As of 2014-12-25 00:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (159 votes), past polls