本文整理汇总了Python中comoonics.XmlTools.clone_node方法的典型用法代码示例。如果您正苦于以下问题:Python XmlTools.clone_node方法的具体用法?Python XmlTools.clone_node怎么用?Python XmlTools.clone_node使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类comoonics.XmlTools
的用法示例。
在下文中一共展示了XmlTools.clone_node方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getEnterprisecopy
# 需要导入模块: from comoonics import XmlTools [as 别名]
# 或者: from comoonics.XmlTools import clone_node [as 别名]
def getEnterprisecopy(self):
from comoonics import XmlTools
import xml.dom
import odict
import os.path
ret_doc=None
ret_element=None
_sets=odict.Odict()
for _templatefile in self.templatefiles:
_file=open(os.path.join(self.sysreport_templatesbase, _templatefile),"r")
doc=XmlTools.parseXMLFP(_file)
# Initially create ret_doc. Cannot do it before cause we need the doc
if not ret_doc:
ret_doc=XmlTools.getDOMImplementation().createDocument(None, doc.documentElement.tagName, None)
ret_element=ret_doc.documentElement
for _child in doc.documentElement.childNodes:
if _child.nodeType==xml.dom.Node.ELEMENT_NODE:
if _child.hasAttribute("name"):
_sets[_child.getAttribute("name")]=XmlTools.clone_node(_child, ret_doc)
elif _child.nodeType == xml.dom.Node.ATTRIBUTE_NODE:
ret_element.appendChild(XmlTools.clone_node(_child, ret_doc))
# remove the save-sysreport and add it to the end
_save_set= _sets[self.save_set]
del _sets[self.save_set]
_sets[self.save_set]=_save_set
for _set in _sets.values():
Sysreport.logger.debug("getEnterprisecopy() adding child: %s" %_set.getAttribute("name"))
ret_element.appendChild(_set)
del _sets[self.save_set]
del _sets[self.head_set]
self.sets=_sets
return EnterpriseCopy(ret_element, ret_doc)
示例2: _createElement
# 需要导入模块: from comoonics import XmlTools [as 别名]
# 或者: from comoonics.XmlTools import clone_node [as 别名]
def _createElement(filename, document, element=None):
"""
Create an empty file element. If document is given the document is the bases.
@param filename: the filename to be given to the file
@type filename: String
@param document: the xml.dom.Document to use for creating a new element. If None it will be
automatically created
@type document: xml.dom.Document
@param element: if given the element will be used as bases for creating the file element. Default: None (empty element will be created)
@type element: xml.dom.Element
@return: The element and the document being created
@rtype: [xml.dom.Element, xml.dom.Document]
"""
import xml.dom
from comoonics import XmlTools
if not document:
impl=xml.dom.getDOMImplementation()
document=impl.createDocument(None, File.TAGNAME, None)
relement=document.documentElement
elif not element:
relement=document.createElement(File.TAGNAME)
else:
relement=XmlTools.clone_node(element, document)
relement.setAttribute(File.ATTRNAME, filename)
return (relement, document)
示例3: testCloneNode
# 需要导入模块: from comoonics import XmlTools [as 别名]
# 或者: from comoonics.XmlTools import clone_node [as 别名]
def testCloneNode(self):
for doc in self.docs:
doc=doc[0]
buf1=XmlTools.toPrettyXML(doc.documentElement)
buf2=XmlTools.toPrettyXML(XmlTools.clone_node(doc.documentElement))
self.assertEquals(buf1, buf2)