sending out XML from python.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sean Berry

    sending out XML from python.

    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


  • Ryan Paul

    #2
    Re: sending out XML from python.

    On Tue, 11 May 2004 18:27:03 -0700, Sean Berry wrote:
    [color=blue]
    > 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[/color]

    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="%(test1pr op)s"/>
    </doc>
    """%{'test1prop ':'asdf'}

    --Segphault


    Comment

    • Peter Hansen

      #3
      Re: sending out XML from python.

      Sean Berry wrote:
      [color=blue]
      > 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.[/color]

      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

      Comment

      • Paul Prescod

        #4
        Re: sending out XML from python.

        Brad Clements wrote:
        [color=blue]
        > Also consider elementtree
        >
        > http://effbot.org/zone/element-index.htm
        >[/color]

        And pygenx, which is specifically designed for this task:



        And it wouldn't hurt to spend 20 minutes poking around Uche's treatises
        on the topic:

        www.XML.com,Textuality Services,Uche Ogbuji,Tools,Three More For XML Output


        Paul Prescod



        Comment

        • Brad Clements

          #5
          Re: sending out XML from python.

          Also consider elementtree



          --
          Novell DeveloperNet Sysop #5

          _
          "Peter Hansen" <peter@engcorp. com> wrote in message
          news:3o2dnQnr_4 xJDDzdRVn_iw@po wergate.ca...[color=blue]
          > Sean Berry wrote:
          >[color=green]
          > > 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[/color][/color]
          of[color=blue][color=green]
          > > XML to send back to Flash, since Flash MX has the ability to easily[/color][/color]
          parse[color=blue][color=green]
          > > XML to get variables and values.
          > >
          > > I have done some reading on XML in Python, but only stuff I have seen[/color][/color]
          has[color=blue][color=green]
          > > 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.[/color]
          >
          > 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
          > --
          > http://mail.python.org/mailman/listinfo/python-list
          >[/color]




          Comment

          • Uche Ogbuji

            #6
            Re: sending out XML from python.

            Paul Prescod <paul@prescod.n et> wrote in message news:<mailman.4 54.1084368087.2 5742.python-list@python.org >...[color=blue]
            > Brad Clements wrote:
            >[color=green]
            > > Also consider elementtree
            > >
            > > http://effbot.org/zone/element-index.htm
            > >[/color]
            >
            > And pygenx, which is specifically designed for this task:
            >
            > http://software.translucentcode.org/pygenx/
            >
            > And it wouldn't hurt to spend 20 minutes poking around Uche's treatises
            > on the topic:
            >
            > http://www.xml.com/pub/a/2003/10/15/py-xml.html[/color]

            Since emitting XML is usually more complex than people think, I also
            recommend the article in which I go over basic principles:

            www.XML.com,Textuality Services,Uche Ogbuji,Instruction, Programming,Proper XML Output in Python


            --Uche
            Igbo-American immigrant from Nigeria, settled near Boulder, Colorado with my wife, three sons and daughter. Restless mind in a restless body, I do a million things without getting very much truly done

            Comment

            Working...