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

一世执手 提交于 2019-12-20 04:50:46

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/40551076/xml-validation-error-char-0x0-out-of-allowed-range

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!