The stupid question is the question not asked | |
PerlMonks |
Re^2: Parsing HTML/XML with Regular Expressionsby haukex (Archbishop) |
on Oct 18, 2017 at 21:11 UTC ( [id://1201621]=note: print w/replies, xml ) | Need Help?? |
Impressive, thank you! As previously threatened, and as per your comments, some notes on trying to break the regex solution ;-) using names that can be confused with the interesting ones: <divx, aclass="data", ... Good point, but without some trickery those would no longer validate properly as XHTML either. using XML namespaces liberally Indeed, I tested this and it does cause trouble: Unsurprisingly the regex and HTML parsers can't handle it, but a little more surprising is that Mojo::DOM ignores namespaces and therefore fails with the following, and that also XML::Twig has trouble with namespaces, or at least I haven't found the right options yet. Only the XML::LibXML and XML::XSH2 solutions handle this correctly:
(Update: Hmm, even the W3C Validator is having trouble with the namespaces...) using external entities As noted here, even some XML parsers seem to have trouble loading all the external entities. But even entities declared within the document should make life difficult for regexes:
Only the XML::LibXML and XML::Twig solutions handle that correctly, everything else Looks like XML::LibXML <update> and XML::XSH2 </update> are the only ones left standing in this torture test so far! :-) And one more thing: currently entities with hex values like   aren't supported by the regex (although that's not too difficult to fix). Updated since the issue with XML::XSH2 was worked out further down in this thread.
In Section
Meditations
|
|