"be consistent" | |
PerlMonks |
How do I parse XML with repeating attribute values?by 1arryb (Acolyte) |
on Dec 12, 2011 at 17:52 UTC ( [id://943140]=perlquestion: print w/replies, xml ) | Need Help?? |
1arryb has asked for the wisdom of the Perl Monks concerning the following question: 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:
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.
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
Back to
Seekers of Perl Wisdom
|
|