in reply to Retrieving an XML node value with XML::DOM::Lite and XML::Parser
use XML::LibXML; my $string = q| <Root> <A > <B>B value</B> <C> <D d_attribute="d_attribute_value">D_Value</D> </C> </A > <A> <B>B value</B> <C> <D d_attribute="d_attribute_value">D_Value</D> </C> </A> </Root> |; my $doc = XML::LibXML->load_xml(string => $string); my @B = $doc->findnodes("//A/B"); if (@B) { for my $node (@B) { my $val = $node->textContent; print qq|Value of B is: $val\n|; } } my @D = $doc->findnodes("//A/C/D"); if (@D) { for my $node (@D) { my $attr = $node->getAttribute("d_attribute"); print qq|Attribute 'd_attribute' of D is: $attr\n|; my $val = $node->textContent; print qq|Value of D is: $val\n|; } }
|
|---|