[devtools/validators] add an Xml validator able to degrade to Html validation because of views perusing demote_to_html stable
authorAurelien Campeas <aurelien.campeas@logilab.fr>
Thu, 15 Apr 2010 14:06:33 +0200
branchstable
changeset 5276 5037d891e207
parent 5269 2e5bc78d05f3
child 5277 92b827b3830e
[devtools/validators] add an Xml validator able to degrade to Html validation because of views perusing demote_to_html
devtools/htmlparser.py
--- a/devtools/htmlparser.py	Thu Apr 15 12:04:48 2010 +0200
+++ b/devtools/htmlparser.py	Thu Apr 15 14:06:33 2010 +0200
@@ -74,6 +74,21 @@
         Validator.__init__(self)
         self.parser = etree.XMLParser()
 
+class XMLDemotingValidator(SaxOnlyValidator):
+    """ some views produce html instead of xhtml, using demote_to_html
+
+    this is typically related to the use of external dependencies
+    which do not produce valid xhtml (google maps, ...)
+    """
+
+    def preprocess_data(self, data):
+        if data.startswith('<?xml'):
+            self.parser = etree.XMLParser()
+        else:
+            self.parser = etree.HTMLParser()
+        return data
+
+
 class HTMLValidator(Validator):
 
     def __init__(self):