Skip to content

Instantly share code, notes, and snippets.

@x-yuri
Last active October 8, 2021 08:13
Show Gist options
  • Save x-yuri/8725b2176c8bc2b92a46f9da28d530b7 to your computer and use it in GitHub Desktop.
Save x-yuri/8725b2176c8bc2b92a46f9da28d530b7 to your computer and use it in GitHub Desktop.
#libxml2 #lxml #alpine-linux

lxml and libxml2

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:

https://github.com/alpinelinux/aports/commit/95969f8678d272a8171f50e92f97d84b7d889ca8#diff-5f71bd176376cf84bb2498ca7adc3de133ede244de41018593bf0faa2ad1d3d3

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment