[Tutor] XML to Python
Gabriel Farrell
gsf at panix.com
Sat May 7 01:35:01 CEST 2005
On Thu, 5 May 2005, Smith, Jeff wrote:
> I'm able to use the built in XML parser to effect "normal" XML parsing
> usage but frequently, I'm not doing anything to complicated and would
> simply like to translate the XML file into a more "Pythonic" structure.
> What's the best way to do this? Something from the standard libraries
> would be preferable.
I just went through the same process of trying to find a quick and
easy way to parse XML in Python, and ended up choosing ElementTree.
Out of everything I tried (including Amara and minidom), ElementTree
seemed to be the one that made the most intuitive sense.
The only downside is that I don't like the way ElementTree handles
namespaces. My quick and dirty solution was to strip the default
namespace out with re before parsing the file with ElementTree, then
put it back in again after the altered document was written out. I
would rather the default namespace be ignored than an ns0 or ns1 added
in front of every element.
gabe
More information about the Tutor
mailing list