Hi, Monks

I have a program which parses the XML feed from the National Vulnerability Database (http://nvd.nist.gov). You can see a sample of the feed at http://nvd.nist.gov/download/nvdcve-2007.xml (warning: don't open this file in a browser unless you want to wait for awhile). The feed is organized by "entry", each entry being the complete report regarding a single software vulnerability. My problem is with the "vuln_soft" tag which lists each vulnerable piece of software, by product "name" and "vendor", and then version "num" and "edition". The structure of this tag is:

<nvd> <entry> ... <vuln_soft> <prod name="name1", vendor="vendor1"> <vers num="1.0" edition=/> <vers num="1.1" edition=/> ... </prod> <prod name="name2", vendor="vendor2"> <vers num="1.0" edition="ee"/> <vers num="1.1" edition="ee"/> ... </prod> ... </vuln_soft> </entry> <nvd>

This all works fine except when the name attribute for 2 <prod> tags have the same value. This is unfortunate because it's perfectly legitimate for the same "product" to be distributed by 2 different "vendors".

A real-world example of this is the vulnerability CVE-2007-5333 (from the file, above) which reports vulnerabilities in tomcat from 2 vendors, "apache" and "apache_software_foundation", each with different version lists.

... <vuln_soft> <prod vendor="apache" name="tomcat"> <vers num="4.1.10" /> ... </prod> <prod vendor="apache_software_foundation" name="tomcat"> <vers num="4.1" /> ... </prod> </vuln_soft> ...

XML::Simple won't create a list of tomcat entries, by vendor. Instead, it drops all of the tomcat "products" except the last one parsed.

Arguably this isn't well-formed XML (at least, XML::Simple complains about it when I turn on strict mode), but who am I to be arguing with the Feds? Am I going to have to start messing around with custom handlers in XML::Parser? Would that even work with this dodgy XML, since XML::Simple is already based on XML::Parser?

Thanks

Larry Barnett


In reply to How do I parse XML with repeating attribute values? by 1arryb

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.