Retourner au contenu associé (entrée de forum : Shell script / parse XML, limites ?)
Posté par anaseto le 28 novembre 2013 à 21:37. En réponse au message Shell script / parse XML, limites ?. Évalué à 2.
Avec XML::LibXML :
#!/usr/bin/perl use strict; use warnings; use XML::LibXML; my $parser = XML::LibXML->new; my $struct = $parser->parse_file('data.xml'); foreach my $host ($struct->findnodes('//Host')) { my ($name) = grep { $_->getName() eq 'name' } $host->getAttributes(); foreach my $report ($host->findnodes('Report')) { my $id = $report->getAttribute('ID'); my $niveau = $report->getAttribute('niveau'); my ($title) = $report->findnodes('title'); print $name->getValue(), ';', $id, ';', $niveau, ";", $title->to_literal, "\n" ; } }
PS : c'est sans doute pas optimal, c'est la première fois que je parse du xml sérieusement et pas à coups de regexps ;)
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル
# Un petit script perl
Posté par anaseto . En réponse au message Shell script / parse XML, limites ?. Évalué à 2.
Avec XML::LibXML :
PS : c'est sans doute pas optimal, c'est la première fois que je parse du xml sérieusement et pas à coups de regexps ;)