@@ -304,8 +304,7 @@ def insertRoot(self, token):
304304docStr += ' PUBLIC "%s" "%s"' % (self .doctype .publicId or "" ,
305305self .doctype .systemId or "" )
306306docStr += ">"
307- #TODO - this needs to work when elements are not put into the default ns
308- docStr += "<html xmlns='http://www.w3.org/1999/xhtml'></html>"
307+ docStr += "<THIS_SHOULD_NEVER_APPEAR_PUBLICLY/>"
309308
310309try :
311310root = etree .fromstring (docStr )
@@ -321,9 +320,17 @@ def insertRoot(self, token):
321320self .document = self .documentClass ()
322321self .document ._elementTree = root .getroottree ()
323322
324- #Add the root element to the internal child/open data structures
323+ # Give the root element the right name
324+ name = token ["name" ]
325325namespace = token .get ("namespace" ,None )
326- root_element = self .elementClass (token ["name" ],namespace )
326+ if namespace is None :
327+ etree_tag = name
328+ else :
329+ etree_tag = "{%s}%s" % (namespace ,name )
330+ root .tag = etree_tag
331+
332+ #Add the root element to the internal child/open data structures
333+ root_element = self .elementClass (name ,namespace )
327334root_element ._element = root
328335self .document ._childNodes .append (root_element )
329336self .openElements .append (root_element )