This is my XML data
<categories>
<category id="Id001" name="Abcd">
<project> ID_1234</project>
<project> ID_5678</project>
</category>
<category id="Id002" name="efgh">
<project> ID_6756</project>
<project> ID_4356</project>
</category>
</categories>
I need to get the text contents of each <project>
element based on the name
attribute of the containing <category>
element.
I am using Perl with the XML::LibXML
module.
For example, given category name Abcd
i should get the list ID_1234
, ID_5678
.
Here is my code
my $parser = XML::LibXML->new;
$doc = $parser->parse_file( "/cctest/categories.xml" );
my @nodes = $doc->findnodes( '/categories/category' );
foreach my $cat ( @nodes ) {
my @catn = $cat->findvalue('@name');
}
This gives me the category names in array @catn
. But how can I get the text values of each project?