def save_xml(self, xmlparent=None):
     typ = self.nodetype()
     if xmlparent is None:
         assert typ == Document.DOCUMENT_NODE
         xmlnode = Document()
         xmlnode.ownerDocument = xmlnode
     else:
         if typ == Document.ATTRIBUTE_NODE:
             xmlnode = xmlparent.ownerDocument.createAttribute(self.name())
         elif typ == Document.CDATA_SECTION_NODE:
             xmlnode = xmlparent.ownerDocument.createCDATASection()
         elif typ == Document.COMMENT_NODE:
             xmlnode = xmlparent.ownerDocument.createComment(
                 self.attribute("data"))
         elif typ == Document.DOCUMENT_FRAGMENT_NODE:
             xmlnode = xmlparent.ownerDocument.createDocumentFragment()
         elif typ == Document.DOCUMENT_NODE:
             raise UserWarning("cannot create a DOCUMENT_NODE from there")
         elif typ == Document.DOCUMENT_TYPE_NODE:
             raise UserWarning(
                 "cannot create a DOCUMENT_TYPE_NODE from there")
         elif typ == Document.ELEMENT_NODE:
             xmlnode = xmlparent.ownerDocument.createElement(
                 self.nodename())
             for key in self.attributes():
                 xmlnode.setAttribute(key, self.attribute(key))
         elif typ == Document.ENTITY_NODE:
             raise UserWarning("cannot create a ENTITY_NODE from there")
         elif typ == Document.ENTITY_REFERENCE_NODE:
             raise UserWarning(
                 "cannot create a ENTITY_REFERENCE_NODE from there")
         elif typ == Document.NOTATION_NODE:
             raise UserWarning("cannot create a NOTATION_NODE from there")
         elif typ == Document.PROCESSING_INSTRUCTION_NODE:
             xmlnode = xmlparent.ownerDocument.createProcessingInstruction()
         elif typ == Document.TEXT_NODE:
             xmlnode = xmlparent.ownerDocument.createTextNode(
                 self.attribute("data"))
         else:
             raise UserWarning("problem")
         #xml tree save
         xmlparent.appendChild(xmlnode)
     for child in self.children():
         child.save_xml(xmlnode)
     return xmlnode
 def save_xml(self, xmlparent=None):
     typ = self.nodetype()
     if xmlparent is None:
         assert typ == Document.DOCUMENT_NODE
         xmlnode = Document()
         xmlnode.ownerDocument = xmlnode
     else:
         if typ == Document.ATTRIBUTE_NODE:
             xmlnode = xmlparent.ownerDocument.createAttribute(self.name())
         elif typ == Document.CDATA_SECTION_NODE:
             xmlnode = xmlparent.ownerDocument.createCDATASection()
         elif typ == Document.COMMENT_NODE:
             xmlnode = xmlparent.ownerDocument.createComment(self.attribute("data"))
         elif typ == Document.DOCUMENT_FRAGMENT_NODE:
             xmlnode = xmlparent.ownerDocument.createDocumentFragment()
         elif typ == Document.DOCUMENT_NODE:
             raise UserWarning("cannot create a DOCUMENT_NODE from there")
         elif typ == Document.DOCUMENT_TYPE_NODE:
             raise UserWarning("cannot create a DOCUMENT_TYPE_NODE from there")
         elif typ == Document.ELEMENT_NODE:
             xmlnode = xmlparent.ownerDocument.createElement(self.nodename())
             for key in self.attributes():
                 xmlnode.setAttribute(key, self.attribute(key))
         elif typ == Document.ENTITY_NODE:
             raise UserWarning("cannot create a ENTITY_NODE from there")
         elif typ == Document.ENTITY_REFERENCE_NODE:
             raise UserWarning("cannot create a ENTITY_REFERENCE_NODE from there")
         elif typ == Document.NOTATION_NODE:
             raise UserWarning("cannot create a NOTATION_NODE from there")
         elif typ == Document.PROCESSING_INSTRUCTION_NODE:
             xmlnode = xmlparent.ownerDocument.createProcessingInstruction()
         elif typ == Document.TEXT_NODE:
             xmlnode = xmlparent.ownerDocument.createTextNode(self.attribute("data"))
         else:
             raise UserWarning("problem")
             # xml tree save
         xmlparent.appendChild(xmlnode)
     for child in self.children():
         child.save_xml(xmlnode)
     return xmlnode