===
<?xml version="1.0" encoding="UTF-8"?> <oval xsi:schemaLocation="http://oval.mitre.org/XMLSchema/oval#redhat redhat-schema.xsd http://oval.mitre.org/XMLSchema/oval#windows windows-schema.xsd http://oval.mitre.org/XMLSchema/oval#unix unix-schema.xsd http://oval.mitre.org/XMLSchema/oval#independent independent-schema.xsd http://oval.mitre.org/XMLSchema/oval#solaris solaris-schema.xsd http://oval.mitre.org/XMLSchema/oval oval-schema.xsd" xmlns:oval="http://oval.mitre.org/XMLSchema/oval" xmlns="http://oval.mitre.org/XMLSchema/oval" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:redhat="http://oval.mitre.org/XMLSchema/oval#redhat" xmlns:windows="http://oval.mitre.org/XMLSchema/oval#windows"xmlns:sola +ris="http://oval.mitre.org/XMLSchema/oval#solaris"> <generator> <schema_version>4.2</schema_version> <timestamp>20051212102623</timestamp> </generator> <definitions> <definition id="OVAL2" class="vulnerability"> <affected family="redhat"> <redhat:platform>Red Hat Linux 9</redhat:platform> <product>Mutt</product> </affected> </definition> <definition id="OVAL3" class="vulnerability"> <affected family="windows"> <windows:platform>Microsoft Windows 2000</windows:platform> <windows:platform>Microsoft Windows Server 2003</windows:platform> <product>Microsoft Exchange Server 2003</product> </affected> </definition> <definition id="OVAL6" class="vulnerability"> </definition> </definitions> <crap>This is some crap</crap> </oval>
Perl code to extract a subset of the definitions
==================================
use XML::Twig; my $doc=new XML::Twig ( twig_roots => { "definition" => \&parseEntry } ); sub parseEntry { my ($twig,$element)=@_; my $id=$element->att("id"); if ($id eq "OVAL3") { $element->flush(); return 1; } $twig->purge(); return 0; } $doc->parsefile("test.xml"); $doc->flush();
The output
========
<definition class="vulnerability" id="OVAL3"> <affected family="windows"> <windows:platform>Microsoft Windows 2000</windows:platform> <windows:platform>Microsoft Windows Server 2003</windows:platform> <product>Microsoft Exchange Server 2003</product> </affected> </definition> </oval>
Edit: g0n - readmore tags
In reply to XML::Twig question by rjkoop
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |