Skip to content
Snippets Groups Projects
xml_format.py 333 B
Newer Older
  • Learn to ignore specific revisions
  • Jesper Zedlitz's avatar
    Jesper Zedlitz committed
    import xml.etree.ElementTree as ET
    
    
    def is_valid(resource, file):
        """Check if the HTTP response is a well-formed XML document."""
    
        with open(file.name, "rb") as f:
            try:
                ET.parse(f)
                return True
            except ET.ParseError as e:
                resource["error"] = str(e)
                return False