Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: XML dont include parent node

by tangent (Parson)
on Dec 10, 2013 at 17:35 UTC ( [id://1066478]=note: print w/replies, xml ) Need Help??


in reply to XML dont include parent node

This is not a modified Xpath but shows how you can access the child nodes:
use 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
See XML::LibXML::Node

Replies are listed 'Best First'.
Re^2: XML dont include parent node
by zak_s (Initiate) on Dec 10, 2013 at 17:51 UTC

    Thanks this helps.
    one more question is there any way to ignore empty lines when copying nodes? Any expression I can use to delete all empty lines ?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1066478]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2024-04-23 07:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found