madbee has asked for the wisdom of the Perl Monks concerning the following question:
Hello! I'm trying to parse an XML for which I have to find an extract only specific childnodes. The XML file is below:
From the above XML file, I need to extract only the LI_Title nodes where Header = "Include". There can be 1 or many LI_Titles in an xml file and many such sections<Aritcle> <Main> <Sect> <H4>Include</H4> ..... <P1> This is the criteria</P1> <L> <LI> <LI_Label>1.</LI_Label> <LI_Title>Critera 1</LI_Title> </LI> <LI> <LI_Label>2.</LI_Label> <LI_Title>Critera 2</LI_Title> </LI> <LI> <LI_Label>3.</LI_Label> <LI_Title>Critera 3</LI_Title> </LI> <LI> <LI_Label>4.</LI_Label> <LI_Title>Critera 3</LI_Title> </LI> </Sect> </Main> </Article>
I've come up with the following to identify the nodes.But I'm not sure how I can just pull out the LI_Title nodes.So, hoping for some help here.
$dom = $parser->parse_file($file); my $expr = ('//Article//Main//Sect//H3[contains(.,"Include")]|//Articl +e//Main//Sect//H4[contains(.,"Include")]|//Article//Main[contains(.," +Include")]//*[name()="LI"]'); my @nodes=$dom->findnodes($expr); foreach $nod(@nodes) { print "element: ".$nod->nextNonBlankSibling(); }
Thanks in advance.-madbee
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Extracting specific childnodes (xpath whitespace)
by Anonymous Monk on Jul 06, 2013 at 03:19 UTC | |
by madbee (Acolyte) on Jul 06, 2013 at 04:13 UTC | |
by Anonymous Monk on Jul 06, 2013 at 11:57 UTC | |
by Anonymous Monk on Jul 06, 2013 at 22:42 UTC | |
by madbee (Acolyte) on Jul 07, 2013 at 04:50 UTC |