sending out XML from python.

Ryan Paul segphault at sbcglobal.net
Tue May 11 22:47:43 EDT 2004


On Tue, 11 May 2004 18:27:03 -0700, Sean Berry wrote:

> I am going to be doing some programming with a Flash programmer in my
> company.  Most of the online docs about integrating Flash with another
> language use PHP.  I am not a fan of PHP.
> 
> What I would really like to do is use Python to create data in the form of
> XML to send back to Flash, since Flash MX has the ability to easily parse
> XML to get variables and values.
> 
> I have done some reading on XML in Python, but only stuff I have seen has
> been geared toward reading in XML data, not spitting it out.
> 
> Is there a module for doing this?  I know that I can make something that
> would work, but wondered if it is already done.
> 
> Thanks

Absolutely! My favorite way is to use the minidom to construct an XML
document in memory, and then use node.toxml() to generate the content.
(You can also use toprettyxml() while you are debugging if you want it to
be readable.) The python documentation has lots of good information about
the available XML tools. I made a wrapper for the minidom that lets me use
simple operators to append nodes and traverse the tree.

Additionally, I sometimes find that it is easier to make an xml output
function in a particular class that builds an xml document from the class
dictionary.

Also, in some situations, it may make more sense just to write out the xml
code and replace parts of it with python:

"""
<doc>
  <test1 prop="%(test1prop)s"/>
</doc>
"""%{'test1prop':'asdf'}

--Segphault





More information about the Python-list mailing list