Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: XML::Twig Question

by Ieronim (Friar)
on Jul 29, 2006 at 19:59 UTC ( [id://564558]=note: print w/replies, xml ) Need Help??


in reply to XML::Twig Question

Consider the following code (it works as expected):
#!/usr/bin/perl use warnings; use strict; use XML::Twig::XPath; my $twig = XML::Twig::XPath->new( pretty_print => 'indented', ); $twig->parse(<<'XML'); <?xml version="1.0"?> <article> <label>here label for testing</label> <fig id="fig001" position="float"><label>Fig. 1.</label><caption><p>fi +rst</p></caption></fig> <fig id="fig002" position="float"><label>Fig. 2.</label><caption><p>se +cond</p></caption></fig> <fig id="fig003" position="float"><label>Fig. 3.</label><caption><p>th +ird</p></caption></fig> <fig id="fig004" position="float"><label>Fig. 4.</label><caption><p>fo +urth</p></caption></fig> <fig id="fig006" position="float"><caption><p>sixth</p></caption></fig +> <fig id="fig005" position="float"><label>Fig. 5.</label><caption><p>fi +fth</p></caption></fig> <fig id="fig006" position="float"><label>Fig. 6.</label><caption><p>si +xth</p></caption></fig> <fig id="fig006" position="float"><label>Fig. 6.</label></fig> </article> XML my @labels = $twig->findnodes('/article/fig[label and caption]/label') +; my @captions = $twig->findnodes('/article/fig[label and caption]/capti +on'); for my $i (0..$#labels) { $labels[$i]->move('first_child', $captions[$i]); } $twig->print;

     s;;Just-me-not-h-Ni-m-P-Ni-lm-I-ar-O-Ni;;tr?IerONim-?HAcker ?d;print

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://564558]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2024-04-25 15:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found