amarks
October 16, 2024, 9:57pm
1
I want to use the lxml 3rd party library within Ignition.
How do I add it and will the library be included with a gateway backup? - if not, what would be the best way to "bundle" it so that the scripting that relies on it will have the library available?
TIA
pturmel
October 16, 2024, 10:01pm
3
You cannot:
The lxml XML toolkit is a Pythonic binding for the C libraries libxml2 and libxslt.
Even if you could use it, it would live in user-lib/pylib
, which is not included in gateway backups.
Use java's native XML support. Helpers available here: xml.py
2 Likes
amarks
October 17, 2024, 1:28pm
4
Ok, I see in the lxml description that it uses Cython and Ignition uses Jython.
Just curious, how do I tell what version of Jython Ignition uses?
edit: nevermind - it's the first thing that prints in the script console interpreter. You can also get it directly via
import sys
print sys.version_info
In general, a Python library needs to be compatible with Python 2.7 and not use native/C code in order to be used in Ignition / run on Jython.
amarks
October 17, 2024, 3:49pm
6
Luckily xml.etree.ElementTree
is basically the same implementation, minus the support for CDATA, but I'll just use string.format() for that anyway.
CDATA = '<![CDATA[{cdata}]]>'
desc = ET.SubElement(tag, 'Description')
desc.text = CDATA.format(cdata = tag_desc)
Don't use ElementTree. Like most of the jython standard library, its handling of international strings/encodings is broken.
Use the java XML standard classes. Full stop.