in reply to Extraction of value with XMLLIB
/mdc/md/mi/mt[contains(.,"VAL")]
The same holds for the <r> elements: their parent is <mv>.
The following works for me:
#!/usr/bin/perl use warnings; use strict; use feature qw{ say }; use XML::LibXML; my @val; my $doc = 'XML::LibXML'->load_xml( location => 'file.xml' ); for my $book ($doc->findnodes('/mdc/md/mi/mt[contains(.,"VAL")]')) { my $order = 1 + $book->findvalue('count(preceding-sibling::mt)'); my $rs = $book->findnodes("../mv/r[$order]"); say join ', ', map $_->textContent, $book, @$rs; }
You can get the same logic with XML::XSH2, which is a wrapper around XML::LibXML:
open file.xml ; for /mdc/md/mi/mt[xsh:match(.,'^VAL[0-9]+')] { my $order = 1 + count(preceding-sibling::mt) ; echo xsh:join(', ', (.), ../mv/r[$order]) ; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Extraction of value with XMLLIB
by shak (Initiate) on May 06, 2015 at 12:04 UTC | |
by choroba (Cardinal) on May 06, 2015 at 12:16 UTC | |
by shak (Initiate) on May 06, 2015 at 12:20 UTC | |
by Anonymous Monk on May 08, 2015 at 06:57 UTC |