Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi again

I was fortunate enough yesterday to have the author of XML::Twig answer my question, and Mirod was very helpful, but unfortunately I still have one question remaing that I can't seem to find the answer to in the perldoc or elsewhere. I'm using the following code

#!/perl/bin/perl -w use strict; use XML::Twig; my $twig= new XML::Twig; open( XML_OUT, ">output.xml") or die $!; $twig->parsefile( "RoamAboutAP_172.108.251.49.xml"); my $root= $twig->root; my $children= $twig->children; my @ds= $root->children('ds'); my @rra= $children-> # Not sure of the syntax for children of children +; foreach my $attr (@ds) { my $test= "TESTING PLACEMENT FOR DS"; my $eblg= new XML::Twig::Elt( 'Average', $test); $eblg->paste( 'first_child', $attr); } foreach my $attr (@rra) { my $test= "TESTING PLACEMENT FOR RRA"; my $eblg= new XML::Twig::Elt( 'Average', $test); $eblg->paste( 'first_child', $attr); } # $twig->set_pretty_print('indented'); $twig->print( \*XML_OUT); close XML_OUT;
This is my pseudo XML file:
<root> <child> <children>foo_bar</children> </child> </root>
How can I navigate to a specific child of root, i.e. child or children?

Thanks again for all the help

Replies are listed 'Best First'.
Re: XML Twig children
by Anonymous Monk on Jan 21, 2003 at 16:49 UTC
    Well, after digging through the perldoc I found the answer..It simply involves using "get_xpath"