MCPcopy Create free account
hub / github.com/Sigil-Ebook/Sigil / WellFormedXMLErrorCheck

Function WellFormedXMLErrorCheck

src/Resource_Files/python3lib/xmlprocessor.py:120–143  ·  view source on GitHub ↗
(data, mtype="")

Source from the content-addressed store, hash-verified

118
119# data is expectedd to be in unicode
120def WellFormedXMLErrorCheck(data, mtype=""):
121 newdata = _remove_xml_header(data)
122 if isinstance(newdata, str):
123 newdata = newdata.encode('utf-8')
124 line = "-1"
125 column = "-1"
126 message = "well-formed"
127 try:
128 parser = etree.XMLParser(encoding='utf-8', recover=False, resolve_entities=True)
129 tree = etree.parse(BytesIO(newdata), parser)
130 except Exception:
131 line = "0"
132 column = "0"
133 message = "exception"
134 if len(parser.error_log) > 0:
135 error = parser.error_log[0]
136 message = error.message
137 if isinstance(message, bytes):
138 message = message.decode('utf-8')
139 line = "%d" % error.line
140 column = "%d" % error.column
141 pass
142 result = [line, column, message]
143 return result
144
145
146def IsWellFormedXML(data, mtype=""):

Callers 1

IsWellFormedXMLFunction · 0.85

Calls 5

XMLParserMethod · 0.80
_remove_xml_headerFunction · 0.70
encodeMethod · 0.45
parseMethod · 0.45
decodeMethod · 0.45

Tested by

no test coverage detected