Reputation: 3282
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
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
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