| Subject: | Re: [Kc] Perl Question: XML::Twig module |
|---|---|
| From: | Daryl Fallin |
| Date: | Mon, 28 Jun 2010 10:12:00 -0500 |
|
All - Figured out the problem. Sterling Hanenkamp got me going in the right direction. Anyway... I was using an abstract example to ask my question, so here is an explanation and my actual code. I am working with the Qualys API and I wanted to pull all scan data back from Qualys so that I can store and mashup the data against other data sources. The DTD for the Qualys xml is: https://qualysapi.qualys.com/scan-1.dtd (This will give you the structure of the XML file) Here is the basic code that I ended up with. This works on the xml file after being retrieved from Qualys. ************************************************* #!/usr/bin/perl
-w # Indentation style: 1 tab = 4 spaces require XML::Twig; sub info { my ($xml, $info) = @_; my $elt = $info; printf "VALUE: %s \n", $elt->parent->parent->parent->att("value"); printf "ENT: %s \n", $elt->is_elt; } if ($elt->is_elt =~ m/(OS|NETBIOS_HOSTNAME)/) { printf "VALUE: %s \n", $elt->parent->att("value"); printf "ENT: %s \n", $elt->is_elt; printf "%s\n", $elt->text; } while ($elt= $elt->next_elt($info) ) { if ($localname ne '#CDATA' && $localname ne '#PCDATA') { printf "%s: ", $localname; printf "%s\n", $elt->text; } } printf "\n\n"; } #=================================================== #Main program section $xml = new XML::Twig( TwigHandlers => { VULN => \&info, OS => \&info, NETBIOS_HOSTNAME => \&info, INFO => \&info, PRACTICE => \&info, HEADER => \&info, #_all_ => \&info, # not using _all_ to ignore the toplevel SCAN tag }, error_context => 1, ); # Parse the XML $xml->parsefile('sample.xml'); On Fri, Jun 25, 2010 at 7:31 PM, Daryl Fallin <darylvf@xxxxxxxxx> wrote: Hi All .... _______________________________________________ kc mailing list kc@xxxxxx http://mail.pm.org/mailman/listinfo/kc |
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| ||
| Previous by Date: | [Kc] Perl Question: XML::Twig module, Daryl Fallin |
|---|---|
| Previous by Thread: | [Kc] Perl Question: XML::Twig module, Daryl Fallin |
| Indexes: | [Date] [Thread] [Top] [All Lists] |