in reply to XML dont include parent node
See XML::LibXML::Nodeuse XML::LibXML; my $string = q| <Root> <Parent> <child1>Child 1</child1> <child2>Child 2</child2> <child3>Child 3</child3> </Parent> </Root>|; my $doc = XML::LibXML->load_xml(string => $string); my @nodes = $doc->findnodes('//Parent'); for my $node (@nodes) { my @childnodes = $node->childNodes or next; for my $cnode (@childnodes) { if ($cnode->nodeName =~ m/^child/) { print 'name: '. $cnode->nodeName . ', '; print 'content: '. $cnode->textContent ."\n"; } } } # Output: # name: child1, content: Child 1 # name: child2, content: Child 2 # name: child3, content: Child 3
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: XML dont include parent node
by zak_s (Initiate) on Dec 10, 2013 at 17:51 UTC |