lxml and SimpleXMLWriter

Discussion in 'Python' started by Srijit Kumar Bhadra, Jul 1, 2006.

  1. I am new to lxml. I am interested to know the equivalent code using
    lxml (http://cheeseshop.python.org/pypi/lxml/1.1alpha). The code is
    taken from http://effbot.org/zone/xml-writer.htm

    from elementtree.SimpleXMLWriter import XMLWriter
    import sys

    w = XMLWriter(sys.stdout)

    html = w.start("html")

    w.start("head")
    w.element("title", "my document")
    w.element("meta", name="generator", value="my application 1.0")
    w.end()

    w.start("body")
    w.element("h1", "this is a heading")
    w.element("p", "this is a paragraph")

    w.start("p")
    w.data("this is ")
    w.element("b", "bold")
    w.data(" and ")
    w.element("i", "italic")
    w.data(".")
    w.end("p")

    w.close(html)

    Best Regards,
    Srijit
    Srijit Kumar Bhadra, Jul 1, 2006
    #1
    1. Advertising

  2. Fredrik Lundh, Jul 1, 2006
    #2
    1. Advertising

  3. Srijit Kumar Bhadra wrote:
    > I am new to lxml. I am interested to know the equivalent code using
    > lxml (http://cheeseshop.python.org/pypi/lxml/1.1alpha). The code is
    > taken from http://effbot.org/zone/xml-writer.htm
    >
    > from elementtree.SimpleXMLWriter import XMLWriter
    > import sys
    >
    > w = XMLWriter(sys.stdout)
    >
    > html = w.start("html")

    [snip]

    Note that the SimpleXMLWriter is in no way related to the ElementTree
    implementation. Feel free to copy the module from the elementtree package and
    use it with lxml.

    Stefan
    Stefan Behnel, Jul 6, 2006
    #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. Erik  Bethke
    Replies:
    3
    Views:
    409
    Erik Bethke
    Feb 8, 2005
  2. Chas Emerick

    lxml/ElementTree and .tail

    Chas Emerick, Nov 15, 2006, in forum: Python
    Replies:
    30
    Views:
    1,294
    Damjan
    Nov 19, 2006
  3. Replies:
    1
    Views:
    412
  4. Laurent Pointal

    lxml and identification of elements in source

    Laurent Pointal, Sep 19, 2007, in forum: Python
    Replies:
    1
    Views:
    359
    Stefan Behnel
    Sep 20, 2007
  5. Silfheed

    CDATA and lxml

    Silfheed, Apr 11, 2008, in forum: Python
    Replies:
    5
    Views:
    372
    Silfheed
    Apr 11, 2008
Loading...

Share This Page