smith
smith

Reputation: 3282

xml::Twig and findnodes

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?

Upvotes: 4

Views: 1740

Answers (2)

mirod
mirod

Reputation: 16171

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

my @c = $_->findvalue('./a/');

Upvotes: 2

Dotan Dimet
Dotan Dimet

Reputation: 490

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.

Upvotes: 4

Related Questions