in reply to XML data reading/output

In other words, you want to dump the elements that match XPath
//descriptors[@type="CTC"]/descriptor/mainterm

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
//descriptors[type="CTC"]/mainterm
to
//descriptors[@type="CTC"]/descriptor/mainterm
as per reply.

Replies are listed 'Best First'.
Re^2: XML data reading/output
by ramrod (Priest) 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').