This project has moved. For the latest updates, please go here.
1

Closed

Update ElementTree to IronPython compatible version

description

The ElementTree implementation in IPY 2.6 and 2.7 is broken:
 
from xml.etree import ElementTree as ET
from StringIO import StringIO
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

 
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.
 
[1] http://effbot.org/zone/element-index.htm
[2] http://code.google.com/p/robotframework/wiki/DotNetSupport
[3] http://docs.python.org/library/xml.etree.elementtree.html
Closed Oct 23, 2011 at 10:51 PM by jdhardy
Fixed in 2.7.1.

comments

jdhardy wrote Oct 16, 2011 at 6: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 6:25 AM

adal wrote Oct 17, 2011 at 11:18 PM

This is still broken. The SimpleXMLTreeBuilder.py 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 ElementIron.py:

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

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

wrote Oct 18, 2011 at 3:51 PM

jdhardy wrote Oct 22, 2011 at 6:33 AM

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

wrote Oct 23, 2011 at 10:51 PM

wrote Feb 22, 2013 at 1:09 AM

wrote May 16, 2013 at 12:03 PM