In libxml-2.9.11
incompatible changes were made
? https://gitlab.gnome.org/GNOME/libxml2/-/commit/dc6f009280e6108fe25f4c4ce32e18fb69cf496e
that broke lxml
:
https://bugs.launchpad.net/lxml/+bug/1928795
https://gitlab.gnome.org/GNOME/libxml2/-/issues/255
The issue was fixed after releasing libxml2-2.9.12
(not yet released):
https://gitlab.gnome.org/GNOME/libxml2/-/commit/85b1792e37b131e7a51af98a37f92472e8de5f3f
Alpine Linux added the fix in 3.14
:
a.sh
:
#!/bin/sh -eu
apk add build-base libxml2-dev libxslt-dev
pip install lxml==4.6.3
cat <<PY > a.py
from lxml import etree
xml = '''<?xml version="1.0" encoding="UTF-8"?>
<a>
<b>
</b>
</a>
'''
t = etree.fromstring(xml.encode()).getroottree()
print(etree.tostring(
t.xpath('/a/b')[0],
encoding=t.docinfo.encoding,
).decode())
PY
python a.py
$ chmod u+x a.sh
$ docker run --rm -itv $PWD/a.sh:/a.sh python:3.6-alpine3.13 ./a.sh
...
<b>
</b>
</a>