I am trying to create an XML document in memory, so the root child nodes require a namespace.
The resulting document should look something like this:
<Feed> <FeedEntity Id="0000" xmlns="http://schemas.example.com/search/query/2010/5/revision"> <FeedRequest locale="en-US" title="<some value>"/> </FeedEntity> ... another FeedEntity element ... </Feed>
However, when I print a document that I created using the ElementTree lib, it looks something like this:
<Feed> <ns0:FeedEntity Id="0000" xmlns:ns0="http://schemas.example.com/search/query/2010/5/revision"> <FeedRequest locale="en-US" title="<some value>"/> </ns0:FeedEntity> </Feed>
This is how I create a document:
counter = 0 namespace = "http://schemas.example.com/search/query/2010/5/revision" root = Element("Feed") node_name = "{%s}FeedEntity" % (namespace, ); feed_entity_element = Element(node_name) feed_entity_element["Id"] = "%04d" % (counter,); feed_request_element = Element("FeedRequest"); feed_request_element["Culture"] = self.culture; feed_request_element["Query"] = address;
How do I get rid of the "ns0" parts in the final XML, so that it looks more like the first example noted above?
source share