Re: extracting nodes from nodes
Michael Ludwig <[email protected]> Thu, 9 May 2013 08:23:46 +0200
| Newsgroups | gmane.comp.lang.perl.xml |
|---|---|
| Message-ID | <20130509062346.GM4472@Dago> |
Grant McLean schrieb am 09.05.2013 um 15:53 (+1200):
> On Tue, 2013-05-07 at 22:19 +0200, Anne Schumann wrote:
>
> > using XML::XPATH, I extract rather big modes from a document. After
> > that, is it possible to go on extracting subnodes from these by
> > iterating over every node retrieved from the nodelist?
> With libxml, if you use an XPath expression to find a list of nodes, you
> can use each node as the starting point for another XPath search, e.g.:
>
> foreach my $datacenter ( $doc->findnodes('//DataCenter') ) {
>
> foreach my $server ( $datacenter->findnodes('.//Server') ) {
>
> my $hostname = $server->findvalue('./@hostname');
And this might also be done in just one search:
//DataCenter//Server/@hostname
And this is still a very simple query example. Most queries you might
want to run can be done in just one query. XPath is a very expressive
query language. Splitting queries up will result in more Perl code.
Michael
_______________________________________________
Perl-XML mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs