I have the following OVAL definintion and want to parse it and store it on specific perl object like a array ref and then accessing it as object
for example to access the first comment attrbitue of the below xml :
<criteria operator="OR">
<criteria operator="AND">
<criterion test_ref="oval:org.mitre.oval:tst:123" comment="Windows XP is installed"/>
<criterion test_ref="oval:org.mitre.oval:tst:234" comment="file foo.txt exists"/>
</criteria>
<criteria operator="AND" negate="true">
<criterion test_ref="oval:org.mitre.oval:tst:345" comment="Windows 2003 is installed"/>
<criterion test_ref="oval:org.mitre.oval:tst:456" comment="file fred.txt has a version less than 2"/>
<criterion test_ref="oval:org.mitre.oval:tst:567" negate="true" comment=patch is installed"/>
</criteria>
<criterion test_ref="oval:org.mitre.oval:tst:345" comment="Windows 2003 is installed"/>
</criteria>
it will be somthing like this:
$arr->[0]->[1]->{oval-org-mitre-oval-tst-123}->{comment}
I tried to parse it with XML::Twig handlers and i get the criteria element but i didn't know how to treat a nested criteria elements in order to build my perl object/data structure
any idea how can i achieve this with XML::Twig and perl ?
You can try to select
<criteria>
elements usingtwig_handlers()
and inside them the<criterion>
elements withchildren()
, and save either attributes in a hash that is pushed into an array ref variable.With your fixed
xml
file,$arr
will be like: