Tracy Ann Monteiro Tracy Ann Monteiro - 6 months ago 36
reST (reStructuredText) Question

XML validation error: Char 0x0 out of allowed range.

How do I handle invalid characters to be able to parse through the data in Python?

I am currently using a REST API to obtain data from a source that produces data in the XML format. However the XML data contains these characters: ¿¿

When trying to validate the data, I get the error at this point which says:

Char 0x0 out of allowed range.

Due to which I am unable to parse this data. I'm not sure how to encode this data. What can I do to solve this problem?


0x0 (aka NUL) is not an allowed character in XML :

[2] Char ::= #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]

Therefore your data is not XML, and any conformant XML processor must report an error such as the one you received.

You must repair the data by removing any illegal characters by treating it as text, not XML, manually or automatically before using it with any XML libraries.

For Python, see Removing control characters from a string in python for tips on how to remove NUL from a string. This must be done before treating the data as XML.