xml.etree.ElementTree: etree Not Found

A very strange thing happened to me today.
I wanted to run this script (from the button and from the script console) with xml.etree.ElementTree, but it says that it cannot be found:


Ignition v8.1.26 on windows server 2019.

This is a sample script from the manual about parsing XML...

I've checked that ElementTree.py exists in the folder named xml.
I've also "upgraded" the gateway with the same version, but no luck.
I've also deleted the .ignition cache folder, but no go.

I have a fairly big project on this gateway, and everything is working fine.
This xml script is only for testing something else, not related to the project on the gateway.

But I'd still like to know why it doesn't work...
Any suggestions?

Huh... nobody....?
@PGriffith maybe... or @Kevin.Herron ...

I've seen this issue with etree before, but never consistently, it's always been a periodic thing that happens in client sessions at runtime. The prevailing thought was that it's some kind of classloader race condition, and we thought we'd squashed it. You're having it consistently happen? That's different, and a bit weird. You're not doing anything like launching async threads, right?

I would contact support, probably. I don't have many other ideas off the top of my head.

You gave me an idea...
I created a new project (empty) with one window and a button with this script in it.
Run designer preview and it works...!?!?
How is that...possible?

I don't ever use the jython xml libraries. I use java's native support, with minimal wrappers:

https://www.automation-pros.com/ignition/xml.py

Use one of strToDoc(), bytesToDoc(), or inputToDoc() to generate a DOM. Use java's native DOM operations to extract what you wish.

I would expect this to be dramatically faster than any jython library, too.

Don't ask about the Vision stuff at the end. Enjoy it if you are so inclined.

3 Likes

What do you mean by that? I work only in Vision... I'm to old to learn Perspective, CSS, HTML,... that's for 'young' people...

And this...?

Read the comments. If it is gibberish to you, you can ignore them. (:

I've figured out what was wrong:
I've put @pturmel xml script to project library under the name 'xml'...


And that conflicts with the import xml.etree.ElementTree as ET since the folder in pylib is also named 'xml'...
I changed the project library script to 'xml2' and now you can import python/jython xml...

2 Likes

Yep I'm having the same issue, trying to load the Icon Manager from Exchange into a project that inherits from a project containing @pturmel's xml project library script. But if I have Icon Manager in a standalone project, it works fine.

Is there a way to alias these imported libraries somehow so I can just rename calls to xml.etree.ElementTree as ET without renaming the xml script as @zxcslo did? I'm sure this would work better with @pturmel's great xml script linked above, but I'm not interested in refactoring a rarely-used backend utility to manage icon sets.

You can bump my library into somePackage.xml if necessary. But it's better to not use jython stdlib.