4
Vote

Implement _elementtree module

description

Not much documentation on this module. It's used by the 'xml' stdlib package.

comments

pekkaklarck wrote Nov 11, 2010 at 4:21 PM

IronPython 2.6.1 already has some code under xml.etree. Unfortunately even this fails:

IronPython 2.6.1 (2.6.10920.0) on .NET 4.0.30319.1
Type "help", "copyright", "credits" or "license" for more information.
from StringIO import StringIO
from xml.etree import ElementTree as ET
ET.parse(StringIO('<test/>'))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Program Files\IronPython 2.6 for .NET 4.0\Lib\xml\etree\ElementTree.py", line 862, in parse
File "C:\Program Files\IronPython 2.6 for .NET 4.0\Lib\xml\etree\ElementTree.py", line 581, in parse
File "C:\Program Files\IronPython 2.6 for .NET 4.0\Lib\xml\etree\ElementTree.py", line 1117, in init
ImportError: No module named expat; use SimpleXMLTreeBuilder instead
It seems SimpleXMLTreeBuilder is not included in xml.etree so basically using the provided ElementTree implementation isn't possible. I just tested that elementtree 1.2.7 preview release [1], which should have better IronPython support than 1.2.6, works well in my project. Does something prevent including it into IronPython?

[1] http://effbot.org/downloads/#elementtree

af001 wrote Dec 16, 2010 at 8:01 AM

The elementtree module is a core component for xml handling in python. It is essential for it to work!

Seo Sanghyeon appears to have written pyexpat/ElementTree for IronPython (a pyexpat emulation for IronPython which lets you use the standard ElementTree module on that platform). At least this should be included into the distribution.

The current ironpython distribution (2.6.1) has the unfortunate approach of providing a module for input that breaks immediately.

pekkaklarck wrote Oct 10, 2011 at 1:14 PM

I'm surprised this issue is considered low priority because not having a working ElementTree implementation in IronPython is a big blocker for many Python programs. I know this is an open source project with limited resources but in this case there already is a working implementation that ought to be easy to take into use (see my nearly a year old comment above about ET 1.2.7).

What's worse than not having ET is having an implementation that can be imported but not used. This means that even if you install a working ET, any code that uses the "standard" way to conditionally import ET (see e.g. http://lxml.de/tutorial.html) still doesn't work because you end up getting a broken ET implementation anyway.

jdhardy wrote Oct 11, 2011 at 3:51 PM

This issue is low priority because it refers to the _elementtree C accelerator module. To make ET work, IronPython needs a pyexpat implmentation ([workitem:20023]) or, as you pointed last year (sorry!), an upgrade to ET.

pekkaklarck wrote Oct 11, 2011 at 7:28 PM

Submitted issue #31579 about changing ET implementation to IPY compatible version.