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. Advertisements

  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. Advertisements

  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. Advertisements

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:
    748
  2. CHANGE username to westes

    Sample Code That Instruments Java Byte Code?

    CHANGE username to westes, Oct 14, 2003, in forum: Java
    Replies:
    1
    Views:
    1,198
    Robert Olofsson
    Oct 14, 2003
  3. Otto Wyss
    Replies:
    5
    Views:
    713
    Robert Vazan
    Sep 7, 2003
  4. Paul Miller

    "drop-in" DOM replacement for minidom?

    Paul Miller, Aug 13, 2003, in forum: Python
    Replies:
    5
    Views:
    651
    Paul Miller
    Aug 15, 2003
  5. Roman Yakovenko

    xml.dom.minidom - bug ? future ?

    Roman Yakovenko, Sep 4, 2003, in forum: Python
    Replies:
    1
    Views:
    477
    =?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?=
    Sep 4, 2003
  6. Hans Nowak
    Replies:
    1
    Views:
    483
    =?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=
    Sep 4, 2003
  7. Replies:
    3
    Views:
    796
    Stefan Behnel
    Aug 3, 2007
  8. Tim Chase
    Replies:
    0
    Views:
    239
    Tim Chase
    Feb 16, 2014
Loading...