xml tree writing with ElementTree; prepends elements with ns0

Discussion in 'Python' started by Alex van der Spek, Oct 11, 2011.

  1. When reading a tree and writing it back to a new file all the elements are
    prepended with the string ns0:

    Why is it prepended and how can I suppress this?

    Thanks,
    Alex van der Spek
     
    Alex van der Spek, Oct 11, 2011
    #1
    1. Advertising

  2. "Alex van der Spek" <> writes:

    > When reading a tree and writing it back to a new file all the elements are
    > prepended with the string ns0:


    That's a namespace prefix.

    >
    > Why is it prepended and how can I suppress this?


    See http://effbot.org/zone/element-namespaces.htm

    I'm not sure you can define the default namespace (i.e., avoid prefixes
    on element names). However, any conformant XML processor should have no
    problem with the output of ElementTree.

    If you're actually producing HTML, then you should say so when calling
    tostring(), by giving the appropriate value to the method argument.

    -- Alain.
     
    Alain Ketterlin, Oct 11, 2011
    #2
    1. Advertising

  3. Alain Ketterlin <-strasbg.fr> writes:

    > "Alex van der Spek" <> writes:
    >
    >> When reading a tree and writing it back to a new file all the elements are
    >> prepended with the string ns0:

    >
    > That's a namespace prefix.
    >
    >>
    >> Why is it prepended and how can I suppress this?

    >
    > See http://effbot.org/zone/element-namespaces.htm
    >
    > I'm not sure you can define the default namespace (i.e., avoid prefixes
    > on element names). However, any conformant XML processor should have no
    > problem with the output of ElementTree.


    Sorry, it looks like you can with ET 1.3: see
    http://effbot.org/zone/elementtree-13-intro.htm

    > If you're actually producing HTML, then you should say so when calling
    > tostring(), by giving the appropriate value to the method argument.
    >
    > -- Alain.
     
    Alain Ketterlin, Oct 11, 2011
    #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. Stub

    B tree, B+ tree and B* tree

    Stub, Nov 12, 2003, in forum: C Programming
    Replies:
    3
    Views:
    10,129
  2. =?utf-8?q?Bj=C3=B6rn_Lindstr=C3=B6m?=

    ElementTree Tidy HTML Tree Builder and comments

    =?utf-8?q?Bj=C3=B6rn_Lindstr=C3=B6m?=, Mar 19, 2005, in forum: Python
    Replies:
    0
    Views:
    359
    =?utf-8?q?Bj=C3=B6rn_Lindstr=C3=B6m?=
    Mar 19, 2005
  3. Kee Nethery
    Replies:
    12
    Views:
    2,091
    Stefan Behnel
    Jun 27, 2009
  4. Stefan Behnel
    Replies:
    0
    Views:
    617
    Stefan Behnel
    Aug 31, 2010
  5. Tharanga Abeyseela

    ElementTree Issue - Search and remove elements

    Tharanga Abeyseela, Oct 17, 2012, in forum: Python
    Replies:
    2
    Views:
    156
    Stefan Behnel
    Oct 17, 2012
Loading...

Share This Page