1

I just tried this python 2.5 snippet to write some XML:

xmldoc = xml.dom.minidom.Document()
feed = xmldoc.createElementNS("http://www.w3.org/2005/Atom", "feed")
xmldoc.appendChild(feed)
print xmldoc.toprettyxml()

I expected the output to look like this:

<?xml version="1.0" ?>
<feed xmlns="http://www.w3.org/2005/Atom" />

Instead I got this:

<?xml version="1.0" ?>
<feed />

Apparently the XML namespace is silently being ignored here. What am I doing wrong?

1 Answer 1

1

minidom does not support namespace normalization. The only workaround I'm aware of is explicitely setting the xmlns attribute with

xmldoc.documentElement.setAttribute('xmlns', 'http://www.w3.org/2005/Atom')
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.