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

Re: XML data reading/output

by ikegami (Pope)
on Sep 04, 2009 at 19:11 UTC ( #793563=note: print w/ replies, xml ) Need Help??

in reply to XML data reading/output

In other words, you want to dump the elements that match XPath


Using XML::LibXML, the syntax is something like

for my $mainterm ( $doc->findnodes( '//descriptors[@type="CTC"]/descriptor/mainterm' +) ) { print $mainterm->toString(); }

XML::Twig would also be awesome here.

Update: Changed
as per reply.

Comment on Re: XML data reading/output
Select or Download Code
Re^2: XML data reading/output
by ramrod (Chaplain) on Sep 04, 2009 at 19:35 UTC
    I got better results with
    $doc->findnodes( '//descriptors[@type="CTC"]/descriptor/mainterm/text( +)'
      The three changes I added are:
    • an @ for the type attribute
    • the /descriptor element (although the xml is not well formed)
    • /text() since it appears they desire a text node
      arg, yeah, dumb mistakes. But not the third one. Contrary to your claims, the OP wants the whole element ('<mainterm weight="a">G</mainterm>'), not just the text ('G').

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (12)
As of 2015-05-26 13:08 GMT
Find Nodes?
    Voting Booth?

    In my home, the TV remote control is ...

    Results (501 votes), past polls