sending out XML from python.

S

Sean Berry

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
 
R

Ryan Paul

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
 
P

Peter Hansen

Sean said:
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.

It's often the case that the simplest thing is just to build
up the strings from scratch. Constructing an awkward
in-memory representation (ala DOM) just to serialize it
immediately can be a trying experience.

How complicated will your XML be?

-Peter
 
U

Uche Ogbuji

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,197
Messages
2,571,041
Members
47,643
Latest member
ashutoshjha_1101

Latest Threads

Top