Python libxml2 cannot parse text streams
See this test case: libxml2-cannot-parse-text.py
Expected output is:
test1
test2
test3
test4
Actual output is:
test1
test2
test3
xmlPythonFileRead: result is not a String
warning <unknown>:1:-1: Unknown IO error
The same problem exists when using the xml.sax.parseString() convenience API: libxml2-cannot-parse-text-2.py.
Root cause is that LibXml2Reader.parse() does [1]:
input = libxml2.inputBuffer(source.getByteStream())
but since source.getByteStream() returns None, this creates an ioWrapper that only ever returns -1 [2], triggering the "result is not a String" error [3].
I don't know what the right way to fix this is, but it looks like in its current state libxml2 cannot be used to parse text strings (as opposed to bytes) at all.
- https://gitlab.gnome.org/GNOME/libxml2/-/blob/67ff748c3eba93745a09157e11759d09f864492f/python/drv_libxml2.py#L149
- https://gitlab.gnome.org/GNOME/libxml2/-/blob/67ff748c3eba93745a09157e11759d09f864492f/python/libxml.py#L73-74
- https://gitlab.gnome.org/GNOME/libxml2/-/blob/67ff748c3eba93745a09157e11759d09f864492f/python/libxml.c#L333
Edited by Maks Verver