本文整理汇总了Python中xml.dom.minidom.Document.unlink方法的典型用法代码示例。如果您正苦于以下问题:Python Document.unlink方法的具体用法?Python Document.unlink怎么用?Python Document.unlink使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xml.dom.minidom.Document
的用法示例。
在下文中一共展示了Document.unlink方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: addToFavorite
# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import unlink [as 别名]
def addToFavorite(game):
doc = None
root = None
if (not os.path.isfile(FAVOURITES_PATH)):
doc = Document()
root = doc.createElement("favourites")
doc.appendChild(root)
else:
doc = parse( FAVOURITES_PATH )
root = doc.documentElement
favNode = doc.createElement("favourite")
root.appendChild(favNode)
favNode.setAttribute( "name", game.title)
favNode.setAttribute( "thumb", game.thumbImage)
url = getGameLaunchUrlAction(game)
textNode = doc.createTextNode(url)
favNode.appendChild(textNode)
doc.writexml(open(FAVOURITES_PATH, 'w'))
doc.unlink()
示例2: testAttributeRepr
# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import unlink [as 别名]
def testAttributeRepr():
dom = Document()
el = dom.appendChild(dom.createElement(u"abc"))
node = el.setAttribute("abc", "def")
confirm(str(node) == repr(node))
dom.unlink()
confirm(len(Node.allnodes) == 0)
示例3: testLegalChildren
# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import unlink [as 别名]
def testLegalChildren():
dom = Document()
elem = dom.createElement('element')
text = dom.createTextNode('text')
try: dom.appendChild(text)
except HierarchyRequestErr: pass
else:
print "dom.appendChild didn't raise HierarchyRequestErr"
dom.appendChild(elem)
try: dom.insertBefore(text, elem)
except HierarchyRequestErr: pass
else:
print "dom.appendChild didn't raise HierarchyRequestErr"
try: dom.replaceChild(text, elem)
except HierarchyRequestErr: pass
else:
print "dom.appendChild didn't raise HierarchyRequestErr"
nodemap = elem.attributes
try: nodemap.setNamedItem(text)
except HierarchyRequestErr: pass
else:
print "NamedNodeMap.setNamedItem didn't raise HierarchyRequestErr"
try: nodemap.setNamedItemNS(text)
except HierarchyRequestErr: pass
else:
print "NamedNodeMap.setNamedItemNS didn't raise HierarchyRequestErr"
elem.appendChild(text)
dom.unlink()
示例4: _testElementReprAndStrUnicode
# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import unlink [as 别名]
def _testElementReprAndStrUnicode():
dom = Document()
el = dom.appendChild(dom.createElement(u"abc"))
string1 = repr(el)
string2 = str(el)
confirm(string1 == string2)
dom.unlink()
示例5: StoreXml
# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import unlink [as 别名]
def StoreXml(self, dValue):
try:
cBasePath=self.GetUpdatePath()
now = datetime.datetime.utcnow()
nowFile='%s-%s' % (now.strftime('%Y%m%d-%H%M%S'), '%04d' % (now.microsecond /1000))
nowXml ='%s:%s' % (now.strftime('%Y%m%d-%H:%M:%S'), '%04d' % (now.microsecond /1000))
doc=Document()
root = doc.createElement("dbUpdate")
for k in ['table', 'operation']:
root.setAttribute( k, dValue[k] )
root.setAttribute( 'datetime', '%s' % nowXml )
doc.appendChild(root)
root.appendChild(self.CreateVersionNode(doc))
root.appendChild(self.CreateRecordNode(doc, dValue))
pathName=os.path.join(cBasePath, '%s' % nowFile)
self._mkdir_recursive(pathName)
fileName=os.path.join(pathName, '%s.xml' % nowFile )
doc.writexml( open(fileName, 'w'),
indent=" ",
addindent=" ",
newl='\n')
doc.unlink()
lEsito=True
except:
lEsito=False
return lEsito
示例6: build_xml_results_batch
# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import unlink [as 别名]
def build_xml_results_batch(results_batch,config):
""" Takes a data structure containing the results of the searchs and builds an xml representation."""
doc=Document()
root=doc.createElement('search_results')
root.setAttribute('guid',config.get('clientid','0000'))
doc.appendChild(root)
for result in results_batch:
video=doc.createElement('video')
video.setAttribute('search-id',str(result['search-id']))
video.setAttribute('video-id',str(result['video-id']))
video.setAttribute('source',result['source'])
title=doc.createElement('title')
title.appendChild(doc.createTextNode(result['title']))
video.appendChild(title)
desc=doc.createElement('description')
if result['description']!=None:
desc.appendChild(doc.createTextNode(result['description']))
else:
desc.appendChild(doc.createTextNode(''))
video.appendChild(desc)
cat=doc.createElement('category')
if result['category']!=None:
cat.appendChild(doc.createTextNode(result['category']))
video.appendChild(cat)
tags=doc.createElement('tags')
if result['tags']!=None:
tags.appendChild(doc.createTextNode(result['tags']))
video.appendChild(tags)
purl=doc.createElement('page_url')
purl.appendChild(doc.createTextNode(result['page_url']))
video.appendChild(purl)
if result['lq_url']!=None:
lq_url=doc.createElement('lq_url')
lq_url.appendChild(doc.createTextNode(result['lq_url']))
video.appendChild(lq_url)
if result['hq_url']!=None:
hq_url=doc.createElement('hq_url')
hq_url.appendChild(doc.createTextNode(result['hq_url']))
video.appendChild(hq_url)
if result['hd_url']!=None:
hd_url=doc.createElement('hd_url')
hd_url.appendChild(doc.createTextNode(result['hd_url']))
video.appendChild(hd_url)
root.appendChild(video)
xml_str=doc.toxml()
doc.unlink()
sanitized_xml_data=''.join([c for c in xml_str if ord(c)<128])
return sanitized_xml_data
示例7: writeDocument
# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import unlink [as 别名]
def writeDocument(sourcePath,targetPath,xmlFileName):
if sourcePath == None or targetPath == None:
return False
## Added May2016. warn user if capabilities are not correct, exit if not a valid layer
if not dla.checkServiceCapabilities(sourcePath,False):
return False
if not dla.checkServiceCapabilities(targetPath,False):
return False
desc = arcpy.Describe(sourcePath)
descT = arcpy.Describe(targetPath)
xmlDoc = Document()
root = xmlDoc.createElement('SourceTargetMatrix')
xmlDoc.appendChild(root)
root.setAttribute("version",'1.1')
root.setAttribute("xmlns:esri",'http://www.esri.com')
dataset = xmlDoc.createElement("Datasets")
root.appendChild(dataset)
prj = dla.getProject()
setSourceTarget(dataset,xmlDoc,"Project",prj.filePath)
setSourceTarget(dataset,xmlDoc,"Source",sourcePath)
setSourceTarget(dataset,xmlDoc,"Target",targetPath)
setSpatialReference(dataset,xmlDoc,desc,"Source")
setSpatialReference(dataset,xmlDoc,descT,"Target")
setSourceTarget(dataset,xmlDoc,"ReplaceBy","")
fieldroot = xmlDoc.createElement("Fields")
root.appendChild(fieldroot)
fields = getFields(descT)
sourceFields = getFields(desc)
sourceNames = [field.name[field.name.rfind(".")+1:] for field in sourceFields]
upperNames = [nm.upper() for nm in sourceNames]
#try:
for field in fields:
fNode = xmlDoc.createElement("Field")
fieldroot.appendChild(fNode)
fieldName = field.name[field.name.rfind(".")+1:]
matchSourceFields(xmlDoc,fNode,field,fieldName,sourceNames,upperNames)
# write the source field values
setSourceFields(root,xmlDoc,sourceFields)
setTargetFields(root,xmlDoc,fields)
# Should add a template section for value maps, maybe write domains...
# could try to preset field mapping and domain mapping...
# add data to the document
writeDataSample(xmlDoc,root,sourceNames,sourcePath,10)
# write it out
xmlDoc.writexml( open(xmlFileName, 'wt', encoding='utf-8'),indent=" ",addindent=" ",newl='\n')
xmlDoc.unlink()
示例8: writeFile
# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import unlink [as 别名]
def writeFile(fileName, persons):
doc = Document()
root = doc.createElement("PersonList")
doc.appendChild(root)
id = 0;
for person in persons:
personList = doc.createElement("Person")
personList.setAttribute("id", str(id))
id += 1
root.appendChild(personList)
print person
# Create Element
tempChild = doc.createElement("name")
personList.appendChild(tempChild)
# Write Text
nodeText = doc.createTextNode(person.name)
tempChild.appendChild(nodeText)
# Create Element
tempChild = doc.createElement("gender")
personList.appendChild(tempChild)
# Write Text
nodeText = doc.createTextNode(person.gender)
tempChild.appendChild(nodeText)
# Create Element
tempChild = doc.createElement("phone")
personList.appendChild(tempChild)
# Write Text
nodeText = doc.createTextNode(person.phone)
tempChild.appendChild(nodeText)
# Create Element
tempChild = doc.createElement("email")
personList.appendChild(tempChild)
# Write Text
nodeText = doc.createTextNode(person.email)
tempChild.appendChild(nodeText)
# Write File
doc.writexml( open((fileName+".xml"), 'w'),
indent=" ",
addindent=" ",
newl='\n')
doc.unlink()
print "ÀÉ®×¼g¤J§¹¦¨!"
示例9: _testElementReprAndStrUnicodeNS
# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import unlink [as 别名]
def _testElementReprAndStrUnicodeNS():
dom = Document()
el = dom.appendChild(
dom.createElementNS(u"http://www.slashdot.org", u"slash:abc"))
string1 = repr(el)
string2 = str(el)
confirm(string1 == string2)
confirm(string1.find("slash:abc") != -1)
dom.unlink()
示例10: testRemoveAttr
# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import unlink [as 别名]
def testRemoveAttr():
dom = Document()
child = dom.appendChild(dom.createElement("abc"))
child.setAttribute("def", "ghi")
confirm(len(child.attributes) == 1)
child.removeAttribute("def")
confirm(len(child.attributes) == 0)
dom.unlink()
示例11: testRemoveAttributeNode
# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import unlink [as 别名]
def testRemoveAttributeNode():
dom = Document()
child = dom.appendChild(dom.createElement("foo"))
child.setAttribute("spam", "jam")
confirm(len(child.attributes) == 1)
node = child.getAttributeNode("spam")
child.removeAttributeNode(node)
confirm(len(child.attributes) == 0)
dom.unlink()
示例12: testDeleteAttr
# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import unlink [as 别名]
def testDeleteAttr():
dom = Document()
child = dom.appendChild(dom.createElement("abc"))
confirm(len(child.attributes) == 0)
child.setAttribute("def", "ghi")
confirm(len(child.attributes) == 1)
del child.attributes["def"]
confirm(len(child.attributes) == 0)
dom.unlink()
示例13: testRemoveAttrNS
# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import unlink [as 别名]
def testRemoveAttrNS():
dom = Document()
child = dom.appendChild(
dom.createElementNS("http://www.python.org", "python:abc"))
child.setAttributeNS("http://www.w3.org", "xmlns:python",
"http://www.python.org")
child.setAttributeNS("http://www.python.org", "python:abcattr", "foo")
confirm(len(child.attributes) == 2)
child.removeAttributeNS("http://www.python.org", "abcattr")
confirm(len(child.attributes) == 1)
dom.unlink()
示例14: save_xml_doc
# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import unlink [as 别名]
def save_xml_doc(self):
material_dict = self.materials.material_dict
doc = Document()
filename = self.parent.filename
materials_xml = doc.createElement("materials")
doc.appendChild(materials_xml)
for name, material in material_dict.items():
material_xml = doc.createElement("material")
materials_xml.appendChild(material_xml)
name_xml = doc.createElement("name")
material_xml.appendChild(name_xml)
name_text = doc.createTextNode(name)
name_xml.appendChild(name_text)
surface_color_xml = doc.createElement( "surface_color")
material_xml.appendChild(surface_color_xml)
red_xml = doc.createElement("red")
surface_color_xml.appendChild(red_xml)
green_xml = doc.createElement("green")
surface_color_xml.appendChild(green_xml)
blue_xml = doc.createElement("blue")
surface_color_xml.appendChild(blue_xml)
red_text = doc.createTextNode(str(material.get_surface_colour()[0]))
red_xml.appendChild(red_text)
green_text = doc.createTextNode(str(material.get_surface_colour()[1]))
green_xml.appendChild(green_text)
blue_text = doc.createTextNode(str(material.get_surface_colour()[2]))
blue_xml.appendChild(blue_text)
transparency_xml = doc.createElement("transparency")
material_xml.appendChild(transparency_xml)
transparency_text = doc.createTextNode(str(material.get_transparency()))
transparency_xml.appendChild(transparency_text)
reflectance_method_xml = doc.createElement("reflectance_method")
material_xml.appendChild(reflectance_method_xml)
reflectance_method_text = doc.createTextNode(str(material.get_reflectance_method()))
reflectance_method_xml.appendChild(reflectance_method_text)
reflectance_xml = doc.createElement("reflectance")
material_xml.appendChild(reflectance_xml)
reflectance_text = doc.createTextNode(str(material.get_reflectance()))
reflectance_xml.appendChild(reflectance_text)
slip_coefficient_xml = doc.createElement("slip_coefficient")
material_xml.appendChild(slip_coefficient_xml)
slip_coefficient_text = doc.createTextNode(str(material.get_slip_coefficient()))
slip_coefficient_xml.appendChild(slip_coefficient_text)
imperviousness_xml = doc.createElement("imperviousness")
material_xml.appendChild(imperviousness_xml)
imperviousness_text = doc.createTextNode(str(material.get_imperviousness()))
imperviousness_xml.appendChild(imperviousness_text)
doc.writexml( open(filename+".xml", 'w'),
indent=" ",
addindent=" ",
newl='\n')
doc.unlink()
示例15: save
# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import unlink [as 别名]
def save(self, filename=None):
if filename is None:
filename = os.path.join(self.schemaPath, self.schemaName)
# create xml document
doc = Document()
schema = doc.createElement("schema")
widgets = doc.createElement("widgets")
lines = doc.createElement("channels")
settings = doc.createElement("settings")
doc.appendChild(schema)
schema.appendChild(widgets)
schema.appendChild(lines)
schema.appendChild(settings)
settingsDict = {}
#save widgets
for widget in self.widgets:
temp = doc.createElement("widget")
temp.setAttribute("xPos", str(int(widget.x())) )
temp.setAttribute("yPos", str(int(widget.y())) )
temp.setAttribute("caption", widget.caption)
temp.setAttribute("widgetName", widget.widgetInfo.fileName)
settingsDict[widget.caption] = widget.instance.saveSettingsStr()
widgets.appendChild(temp)
#save connections
for line in self.lines:
temp = doc.createElement("channel")
temp.setAttribute("outWidgetCaption", line.outWidget.caption)
temp.setAttribute("inWidgetCaption", line.inWidget.caption)
temp.setAttribute("enabled", str(line.getEnabled()))
temp.setAttribute("signals", str(line.getSignals()))
lines.appendChild(temp)
settings.setAttribute("settingsDictionary", str(settingsDict))
xmlText = doc.toprettyxml()
file = open(filename, "wt")
file.write(xmlText)
file.close()
doc.unlink()
if os.path.splitext(filename)[1].lower() == ".ows":
(self.schemaPath, self.schemaName) = os.path.split(filename)
self.canvasDlg.settings["saveSchemaDir"] = self.schemaPath
self.canvasDlg.addToRecentMenu(filename)
self.canvasDlg.setCaption(self.schemaName)