writing xml tree

Discussion in 'Python' started by david farning, Nov 22, 2003.

  1. I am doing my first work in python/xml

    Is is possiable to write a xmlTree in a single command?
    for example

    doc = libxml2.parseFile (filename)
    # add node to doc

    doc.write(filename) ??????????????

    I have seen several examles writing one element or line at a time, but never
    the whole tree.

    Thanks
    Dave Farning
    david farning, Nov 22, 2003
    #1
    1. Advertising

  2. david farning

    Paul Boddie Guest

    david farning <> wrote in message news:<PzQvb.4886$>...
    > I am doing my first work in python/xml
    >
    > Is is possiable to write a xmlTree in a single command?
    > for example
    >
    > doc = libxml2.parseFile (filename)
    > # add node to doc
    >
    > doc.write(filename) ??????????????
    >
    > I have seen several examles writing one element or line at a time, but never
    > the whole tree.


    You can use the serialize method on the document node to get the
    document as text (or on any other node to get a document fragment as
    text):

    s = doc.serialize()
    # Use normal file writing mechanisms.

    Or you could use the saveFile method to write to a file:

    doc.saveFile(filename)

    I'd recommend using Python interactively to see which methods are
    available on the document node:

    import libxml2
    doc = libxml2.parseFile(filename)
    dir(doc)

    Indeed, until I started responding to your question, I hadn't noticed
    saveFile, so there's a lot to discover. ;-)

    Paul
    Paul Boddie, Nov 24, 2003
    #2
    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. Ramkumar Menon

    B+ Tree versus Ternary Search Tree

    Ramkumar Menon, Aug 16, 2005, in forum: Java
    Replies:
    2
    Views:
    1,575
    Roedy Green
    Aug 16, 2005
  2. Joris Gillis
    Replies:
    2
    Views:
    1,515
    Joris Gillis
    Jun 16, 2006
  3. Stub

    B tree, B+ tree and B* tree

    Stub, Nov 12, 2003, in forum: C Programming
    Replies:
    3
    Views:
    10,077
  4. Peter Reimer
    Replies:
    4
    Views:
    1,097
    Peter Flynn
    Apr 12, 2010
  5. Alex van der Spek
    Replies:
    2
    Views:
    338
    Alain Ketterlin
    Oct 11, 2011
Loading...

Share This Page