Hello there

Remember for future questions to be as precise as you can, so that others can help you effectively (consider to read Understanding-and-Using-PerlMonks).

I humbly think that xpath are not intended to do match as in your case (child1, child2, child3..). I also think another design for your data will be better, if you can choice: all tag are 'child' and each one have a numerical 'id'.

In Perl there are many way to get the work done (and speaking about xml they are many * many.. see the poll), so I present a XML::Twig solution. Handlers are subs that are called during parsing, here you can use a normal Perl regex to filter unwanted results (i putted an 'ufo' in the xml data..).
use warnings; use strict; use XML::Twig; my $xml=<<'XML'; <Root> <Parent> <child1>Child 1</child1> <child2>Child 2</child2> <child3>Child 3</child3> <ufo> Ufo there!</ufo> </Parent> </Root> XML my $twig= new XML::Twig( pretty_print => 'indented', twig_handlers => { '/Root/Parent/*' => \&fie +ld }, ); $twig->parse( $xml); sub field { my( $twig, $field)= @_; return unless $field->gi() =~ /^child/i; $field->print; #OR print $field->text(); } #OUTPUT # # <child1>Child 1</child1> # <child2>Child 2</child2> # <child3>Child 3</child3>


Hth
L*
There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

In reply to Re: XML dont include parent node by Discipulus
in thread XML dont include parent node by zak_s

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.