This project has moved and is read-only. For the latest updates, please go here.


Update ElementTree to IronPython compatible version


The ElementTree implementation in IPY 2.6 and 2.7 is broken:
from xml.etree import ElementTree as ET
from StringIO import StringIO
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\", line 862, in parse
File "C:\Program Files\IronPython 2.6 for .NET 4.0\Lib\xml\etree\", line 581, in parse
File "C:\Program Files\IronPython 2.6 for .NET 4.0\Lib\xml\etree\", line 1117, in init
ImportError: No module named expat; use SimpleXMLTreeBuilder instead

ElementTree 1.2.7 preview available at [1] has this comment: "ElementTree 1.2.7 preview is now available. This is 1.2.6 plus support for IronPython.". We've also used this version with Robot Framework [2] and at least in our relatively simple use it works great.
It might be worth checking how ET 1.3 alpha 3 works too. It's newer than 1.2.7 so it could have same IronPython fixes. CPython 2.7 uses ET 1.3 [3] so this would make IPY 2.7 API compatible with CPython 2.7 in this regard.
Notice that there's already work item #21407 about adding _elementtree module for the current ET implementation.
Closed Oct 23, 2011 at 11:51 PM by jdhardy
Fixed in 2.7.1.


jdhardy wrote Oct 16, 2011 at 7:23 PM

Fixed in cb73948.

You'll need to specify SimpleXMLTreeBuilder.TreeBuilder when calling ElementTree.parse, but otherwise it should work.

wrote Oct 17, 2011 at 7:25 AM

adal wrote Oct 18, 2011 at 12:18 AM

This is still broken. The module is not included with IronPython. Besides, "fromstring" should work without having to pass SimpleXMLTreeBuilder.TreeBuilder to it, I'm using the same code with both CPython and IronPython.

ATM I'm using ET 1.2.7, with a small patch in

....# FIXME: handle settings here? (disable comments, etc)

....from System.Xml import XmlReaderSettings, DtdProcessing
....settings = XmlReaderSettings()
....settings.DtdProcessing = DtdProcessing.Ignore
....reader = XmlReader.Create(source, settings)

wrote Oct 18, 2011 at 4:51 PM

jdhardy wrote Oct 22, 2011 at 7:33 AM

Fixed again in 164c804 - thanks @adal for the suggestion.

wrote Oct 23, 2011 at 11:51 PM

wrote Feb 22, 2013 at 2:09 AM

wrote May 16, 2013 at 1:03 PM