4

I have the following xml code snippet :

<a>
  <b> textb <b>
  <c> textc <c>
  <d> textd <d>
<\a>
<a>
  <b> textb <b>
  <c> textc <c>
  <d> textd <d>
<\a>

I use xml::twig to parse it as below :

my @c= map { $_->text."\n" } $_->findnodes( './a/');

and get the textbtextctextd as one element of the array. Is there an option to get with findnodes textb,textc,textd as 3 array elements and not one?

Bitmap
  • 12,402
  • 16
  • 64
  • 91
smith
  • 3,232
  • 26
  • 55

2 Answers2

4

Use the star at the end of the expression:

$_->findnodes( './a/*');

The '*' matches any tag, so you get the 3 child nodes - your current example only matches the 'a', and its text is the concatenation of the text of the nested elements.

Dotan Dimet
  • 490
  • 3
  • 5
2

in XML::Twig 3.39 (and above) you can use findvalue to get an array of strings.

my @c = $_->findvalue('./a/');
daxim
  • 39,270
  • 4
  • 65
  • 132
mirod
  • 15,923
  • 3
  • 45
  • 65