2

I have an XML document which I am reading and appending to using ElementTree. This has multiple namespaces declared. From what I can tell, ElementTree will only allow a single global namespace to be declared: ET.register_namespace(prefix, uri)

I would like to write multiple namespaces out in the resulting file. If I try to manually append them using root.set(prefix, uri) Then they are put in the wrong order, and I get cElementTree.ParseError: unbound prefix: line 2, column 0

Edit: it turns out that I had a typo in the option I was setting. I corrected this, and it re-parses fine. So it looks like this is a viable solution.

Thanks!

1
  • Could you please add more code to your question? Commented Oct 1, 2012 at 12:03

1 Answer 1

1

If you are not restricted to just using the standard library, I suggest you install and use the lxml package which provides the ElementTree API, and it has a number of advantages, including easily allowing you to have multiple namespaces in the same document.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.