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

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

  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. 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. Joris Gillis
    Replies:
    2
    Views:
    1,787
    Joris Gillis
    Jun 16, 2006
  2. Stub

    B tree, B+ tree and B* tree

    Stub, Nov 12, 2003, in forum: C Programming
    Replies:
    3
    Views:
    10,623
  3. =?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:
    476
    =?utf-8?q?Bj=C3=B6rn_Lindstr=C3=B6m?=
    Mar 19, 2005
  4. Kee Nethery
    Replies:
    12
    Views:
    2,604
    Stefan Behnel
    Jun 27, 2009
  5. Peter Reimer
    Replies:
    4
    Views:
    1,326
    Peter Flynn
    Apr 12, 2010
  6. Barak, Ron
    Replies:
    1
    Views:
    1,897
    John Machin
    May 5, 2010
  7. Terry Reedy
    Replies:
    1
    Views:
    695
    John Machin
    May 5, 2010
  8. Replies:
    4
    Views:
    307
    Stefan Behnel
    Dec 15, 2012
Loading...