views:

273

answers:

2

I need to port some code that relies heavily on lxml from a CPython application to IronPython.

lxml is very Pythonic and I would like to keep using it under IronPython, but it depends on libxslt and libxml2, which are C extensions.

Does anyone know of a workaround to allow lxml under IronPython or a version of lxml that doesn't have those C-extension dependencies?

+1  A: 

Something which you might have already considered:

An alternative is to first port the lxml library to IPy and then your code (depending on the code size). You might have to write some C# wrappers for the native C calls to the C extensions -- I'm not sure what issues, if any, are involved in this with regards to IPy.

Or if the code which you are porting is small, as compared to lxml, then maybe you can just remove the lxml dependency and use the .NET XML libraries.

Rohit
Thanks for that info, right now we're seriously considering dumping lxml and going for .Net XML because we just can't use C-extensions at all.
Fabio de Miranda
+1  A: 

You might check out IronClad, which is an open source project intended to make C Extensions for Python available in IronPython.

Jason Jackson
Thanks for you answer and your time, I wish I could use IronClad and it probably would work in most cases.Unfortunately my code will run as an embedded IronPython script inside a ASP.net server and I can't use any native extension at all, even if I could access them.
Fabio de Miranda
I am not an experienced IronPython or Python developer; I am a .Net developer that hobbies in IronPython. Forgive me ignorance here. It looks like lxml is a rather rich API, so it will be hard to replicate. An idea I had was to try to replicate those portions of the lxml API you are currently using. You might look at a project like http://devhawk.net/2008/05/06/Stream+Processing+XML+In+IronPython.aspx for a starting point.
Jason Jackson