本文整理汇总了Python中xml.dom.minidom.Document.ownerDocument方法的典型用法代码示例。如果您正苦于以下问题:Python Document.ownerDocument方法的具体用法?Python Document.ownerDocument怎么用?Python Document.ownerDocument使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xml.dom.minidom.Document
的用法示例。
在下文中一共展示了Document.ownerDocument方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: save_xml
# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import ownerDocument [as 别名]
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