Reputation: 858
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?
Upvotes: 1
Views: 3688
Reputation: 83032
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?
Upvotes: 1
Reputation: 18794
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.
Upvotes: 1