1

So I have an XML string that I want to convert to JSON in Python 3.2. I was going to do that by converting the string to a python object via lxml and then convert the object to JSON via JSONEncoder.

Unfortunately, lxml does not seem to be built for Win32, does anyone have any suggestions for an alternate XML - Python library or XML - JSON library?

8

2 Answers 2

1

xml.etree.ElementTree and its faster sibling xml.etree.cElementTree are included with all Python versions from 2.5 onwards. The Python 3.2 docs are here.

lxml.etree is an implementation of the ElementTree interface with some enhancements and (well-documented) minor differences. However the structure of an Element instance is the same. Is there any particular reason why you must have lxml?

1

I have a super simple script that does this:

XML to Python data structure « Python recipes « ActiveState Code http://code.activestate.com/recipes/534109-xml-to-python-data-structure/

It is mainly for people to reference XML data as an object in Python. For your purpose, you can introspect the node's content in DataNode._attrs and .data.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.