Python XML APIs?

Can anyone comment on the availability of the Python XML APIs on Digi Connectport devices? I am attempting to run a script which communicates with a STOMP message queue, and getting the following error:

ImportError: No module named xml.dom.minidom

Is it possible to provide this module? What are my options here?

Thanks,
Jon

Hi Jon,

The standard XML libraries of python are compatible with the device*. If you have installed python on your machine, you should be able to find them in the /python/libs/xml directory. Under there you will find the xml/dom/minidom.py file as well as the supporting libraries.

If you zip them up using relative paths and upload them to the device, you could do a sys.path.append(‘WEB/python/’) and import the files like normal.

** I believe not all the UTF encodings are available. 8 bit ASCII works though.

Mawr

Thanks, I’ll give that a shot.


Jon

Hi;

I am having an issue importing XML module(s) into my CP X4 Python environment. I would like to use xml.dom.minidom to create XML data for upload to iDigi. As instructed in this post I added the minidom.py module to my driver zip file archive and uploaded it to my X4. When I run my program it attempts to import minidom but results in an error message “ImportError: No module named xml.dom”.

The issue is I do not know where to find the xml.dom module for import into my zip archive. And, since I planned on using xml.dom.minidom not xml.dom, how do I zip this into my archive?

Sincerely

rubout

What I do is copy all the xml folder files and place it into my project src directory and it works well. Obviously the only file you copied lacks other dependencies. Maybe not all the files are necessary, but it will let your app run in a short time.

Hello Mark,

Are you using Digi ESP for Python to develop your Python projects? I ask this because the IDE has a project build process which deals with these kind of errors:

When you compile your project, the Digi ESP runs over the main Python module of your project looking for the imports you have made. Then, it automatically adds the Python modules, from the standard Python library, needed for your project into a zip file. It maintains the directory structure inside the zip file to avoid problems when imported from the remote Digi device.

The Digi ESP generates a launch file for your project adding there the call to the just generated zip file.

One of the cons of this feature is that the Digi ESP will add all the Python modules that are needed by the xml.dom modules (in your case) and their dependencies, and they may be a lot.

If you wanna know more things about the Digi ESP for Python:

http://www.digi.com/products/wireless-wired-embedded-solutions/software-microprocessors-accessories/software/digiesp.jsp#overview

Regards!

I am no XML expert, but 4 years ago I worked with an XML guru on an X4 (when they had only 16MB of RAM) and he put togather a minidom bundle (by magic I guess :-] ) which we included in the ZIP. The files he had were:

  • xml/dom/domreq.py, expatbuilder.py, minicompat.py, minidom.py, NodeFilter.py, xmlbuilder.py
  • xml/parsers/expat.py

As whatcall says, you might need to manually include the files & subdirectory in your zip - Python kind of ‘mounts’ the ZIP as if it were a filesystem, so directory structure is important.

Just be aware that parsing XML takes lots of RAM, so make sure you manually del all reference to the file/source AFTER the parse and call gc.collect(). For example, to parse a 44K source file we’d need up to 2MB of free RAM … which back in 2008 was not easy on the 16MB X4 with only 2-3MB of free RAM when python ran!

Thanks lynnl. I am glad to here you clarified the gateway built-in xbee module baudrate setting.

Actually, all the nodes are routers except coordinator in my network. I change the AR value to 1(*10)sec and the test the rx/tx time interval. The result is even worse than previous. Before this changing , the typical reponse time between request data sent out and response data received is 80ms. But after that change , it is >100ms.

I tested all the modules on my desktop, so I guess the distance is not a big cause. I check the status of the 10 router nodes under test and all their parent address if FFFE (that is coordinator, right?).

A simple solution that may improve the latency is to change the reciever baudrate from 9600bps to a higher value (38400).