minidom sample code

Discussion in 'Python' started by Miranda Evans, Sep 8, 2003.

  1. Seeking sample python script that makes use of of xml.dom.minidom.
    Specifically, would like to see code where xml.dom.minidom is used to
    create an output file the contents of which is an XML document.

    Ideally, the output file would a simple XML document such as the one
    below.

    <?xml version="1.0" ?>
    <TrivialRootTag>TrivialContents</TrivialRootTag>

    Workstation O/S is Win2K; version of Python is 2.2.

    Can anyone point me to a documentation/link/whatever that provides
    such sample code? Thank you.
     
    Miranda Evans, Sep 8, 2003
    #1
    1. Advertising

  2. On 8 Sep 2003 13:51:06 -0700, (Miranda Evans) wrote:

    >Seeking sample python script that makes use of of xml.dom.minidom.
    >Specifically, would like to see code where xml.dom.minidom is used to
    >create an output file the contents of which is an XML document.
    >
    >Ideally, the output file would a simple XML document such as the one
    >below.
    >
    ><?xml version="1.0" ?>
    ><TrivialRootTag>TrivialContents</TrivialRootTag>
    >
    >Workstation O/S is Win2K; version of Python is 2.2.
    >
    >Can anyone point me to a documentation/link/whatever that provides
    >such sample code? Thank you.


    Did you look at the xml.dom.minidom docs at

    http://www.python.org/doc/current/lib/module-xml.dom.minidom.html

    Taken from the first page verbatim:

    >>> from xml.dom.minidom import getDOMImplementation
    >>> impl = getDOMImplementation()
    >>> newdoc = impl.createDocument(None, "some_tag", None)
    >>> top_element = newdoc.documentElement
    >>> text = newdoc.createTextNode('Some textual content.')
    >>> top_element.appendChild(text)

    <DOM Text node "Some textu...">

    Using the methods described on the second page:

    >>> newdoc.toxml()

    '<?xml version="1.0" ?>\n<some_tag>Some textual content.</some_tag>'

    or:

    >>> newdoc.toprettyxml()

    '<?xml version="1.0" ?>\n<some_tag>\n\tSome textual content.\n</some_tag>\n'

    and showing what that looks like printed:

    >>> print newdoc.toprettyxml()

    <?xml version="1.0" ?>
    <some_tag>
    Some textual content.
    </some_tag>

    I'll leave it to you to change the spelling to match your example ;-)

    Regards,
    Bengt Richter
     
    Bengt Richter, Sep 9, 2003
    #2
    1. Advertising

  3. Re: minidom sample code (OT)

    >>> from xml.dom.minidom import getDOMImplementation

    It needs much more time to import this package than
    any other one. As much that it's perceptible compared
    to other packages.

    Because my main debugger is print i don't like if an
    application needs much more time. Is there a way around?

    Manuel
     
    Manuel Huesser, Sep 9, 2003
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jake
    Replies:
    0
    Views:
    604
  2. Replies:
    3
    Views:
    557
    Stefan Behnel
    Aug 3, 2007
  3. Tim Chase
    Replies:
    0
    Views:
    96
    Tim Chase
    Feb 16, 2014
  4. Terry Reedy
    Replies:
    0
    Views:
    106
    Terry Reedy
    Feb 16, 2014
  5. Tim Chase
    Replies:
    0
    Views:
    102
    Tim Chase
    Feb 16, 2014
Loading...

Share This Page