• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python dom.appendChild函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中xml.dom.appendChild函数的典型用法代码示例。如果您正苦于以下问题:Python appendChild函数的具体用法?Python appendChild怎么用?Python appendChild使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了appendChild函数的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: add

    def add(self, doc):
	#print "$$$$$$$$$$$$$ called add()"
	objs = doc.getElementsByTagName("obj")
	for obj in objs:
	    tu = self.root.createElement("tu")
	    
	    klass = obj.getAttribute("class")
	    name = obj.getAttribute("name")
	    
	    sets = obj.getElementsByTagName("sets")
	    for set in sets:
		tuCommandName = set.getAttribute("attr")
		if set.firstChild.TEXT_NODE:
		    #print "$$$$$$ ok"
		    tuCommand = set.firstChild.data
		    tuCommand = tuCommand.replace("\"","")
		    tuCommand = tuCommand.replace("'","")
		    tuCommand = tuCommand.replace("(","")
		    tuCommand = tuCommand.replace(")","")
		
		    tu.setAttribute("class",klass)
		    tu.setAttribute("who",name)
		    tu.setAttribute("prop",tuCommandName)
		    tu.setAttribute("value",tuCommand)
		
		    newStr = self.root.createTextNode("\n")
		    
		    dom = self.root.getElementsByTagName("root").item(0)
		    
		    dom.appendChild(tu)
		    dom.appendChild(newStr)
		else:
		    print "ОШИБКА в файле "+str(self.fileName)+" (пропущено) "
开发者ID:boris-r-v,项目名称:ArmDsp-Generator,代码行数:33,代码来源:tu.py


示例2: testLegalChildren

def testLegalChildren():
    dom = Document()
    elem = dom.createElement('element')
    text = dom.createTextNode('text')

    try: dom.appendChild(text)
    except xml.dom.HierarchyRequestErr: pass
    else:
        print "dom.appendChild didn't raise HierarchyRequestErr"

    dom.appendChild(elem)
    try: dom.insertBefore(text, elem)
    except xml.dom.HierarchyRequestErr: pass
    else:
        print "dom.appendChild didn't raise HierarchyRequestErr"

    try: dom.replaceChild(text, elem)
    except xml.dom.HierarchyRequestErr: pass
    else:
        print "dom.appendChild didn't raise HierarchyRequestErr"

    nodemap = elem.attributes
    try: nodemap.setNamedItem(text)
    except xml.dom.HierarchyRequestErr: pass
    else:
        print "NamedNodeMap.setNamedItem didn't raise HierarchyRequestErr"

    try: nodemap.setNamedItemNS(text)
    except xml.dom.HierarchyRequestErr: pass
    else:
        print "NamedNodeMap.setNamedItemNS didn't raise HierarchyRequestErr"

    elem.appendChild(text)
    dom.unlink()
开发者ID:BmanGames,项目名称:Toontown-Level-Editor,代码行数:34,代码来源:test_minidom.py


示例3: include

    def include(self):

	# Записать эти файлы в storyall.xml
	try:
	    doc = FromXmlFile("storyall.xml")
	    #Print (doc)
	    dom = doc.documentElement

	    inc = doc.createElement("include")
	    inc.setAttribute("url", self.toFile)
	    isIncAlready=False
	    incs = dom.getElementsByTagName("include")
	    for i in incs:
		if i.getAttribute("url")==inc.getAttribute("url"):
		    isIncAlready=True
		    break
	    if not isIncAlready:
		dom.appendChild(inc)
		dom.appendChild(doc.createTextNode("\n"))


	    f=open("storyall.xml", 'w')
	    Print(doc, f, "utf-8")

	except Exception, msg:
	    print "Strelka-Canceler::include(): EXCEPTION (while writing to 'storyall.xml'):", msg
开发者ID:boris-r-v,项目名称:ArmDsp-Generator,代码行数:26,代码来源:canceler.py


示例4: appendStoryallXml

    def appendStoryallXml(self, xmlFile, templates_path,result_path):
	os.system("cp "+xmlFile+" "+xmlFile+".old")
        doc=FromXmlFile(xmlFile)
	dom=doc.getElementsByTagName("root").item(0)
	for file in os.listdir(templates_path):
	    if re.search("\.template\.xml",file) and not re.search("impulses\.", file):
	        try:
	            ff = open(result_path+"/"+file.replace(".template",""),'r')
	            ff.close()
	            include = doc.createElement("include")
	            include.setAttribute("url",file.replace(".template",""))
	            includes = dom.getElementsByTagName("include")
	            isAppend = True
	            for inc in includes:
	                if inc.getAttribute("url") == file.replace(".template",""):
	                    isAppend = False
	            if isAppend:
	                dom.appendChild(include)
	                newStr=doc.createTextNode("\n")
		        dom.appendChild(newStr)
		        print "В storyall.xml добавлена нода "+str(include)
		    else:
		        print "В storyall.xml уже имеется нода <include url='"+file.replace(".template","")+"' />"
		except:
		    continue
																																												
	file=open(xmlFile,'w')
	Print(doc,file,"utf-8")
	print "Записан файл ", str(xmlFile)
开发者ID:boris-r-v,项目名称:ArmDsp-Generator,代码行数:29,代码来源:generator.py


示例5: appendTsXml

    def appendTsXml(self, tsXmlFile):
	os.system("cp "+tsXmlFile+" "+tsXmlFile+".old")
	doc=FromXmlFile(tsXmlFile)
	dom=doc.getElementsByTagName("g").item(0)
	for file in os.listdir(tsXmlFile.replace("/ts.xml","")):
    	    if re.search("impulses\.",file) and re.search("\.xml", file) and not re.search("\.old", file):
		include = doc.createElement("include")
		include.setAttribute("url",file)
	    
		includes = dom.getElementsByTagName("include")
		isAppend = True
		for inc in includes:
		    if inc.getAttribute("url") == file:
			isAppend = False
	    
		if isAppend:
		    dom.appendChild(include)
		    newStr=doc.createTextNode("\n")
		    dom.appendChild(newStr)
		    #Obj.sig(self.out,_("В ts.xml добавлена нода "+str(include)))
		    print _("В ts.xml добавлена нода "+str(include))
		else:
		    #Obj.sig(self.out,_("В ts.xml уже имеется нода <include url='"+file+"' />"))
		    print _("В ts.xml уже имеется нода <include url='"+file+"' />")
	file=open(tsXmlFile,'w')
	Print(doc,file,"utf-8")
	#Obj.sig(self.out,_("Записан файл "+str(tsXmlFile)))
	print "Записан файл ", str(tsXmlFile)
开发者ID:boris-r-v,项目名称:ArmDsp-Generator,代码行数:28,代码来源:generator.py


示例6: _testElementReprAndStrUnicode

def _testElementReprAndStrUnicode():
    dom = Document()
    el = dom.appendChild(dom.createElement(u"abc"))
    string1 = repr(el)
    string2 = str(el)
    confirm(string1 == string2)
    dom.unlink()
开发者ID:BmanGames,项目名称:Toontown-Level-Editor,代码行数:7,代码来源:test_minidom.py


示例7: _testElementReprAndStrUnicodeNS

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()
开发者ID:BmanGames,项目名称:Toontown-Level-Editor,代码行数:9,代码来源:test_minidom.py


示例8: testRemoveAttr

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()
开发者ID:BmanGames,项目名称:Toontown-Level-Editor,代码行数:10,代码来源:test_minidom.py


示例9: testDeleteAttr

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()
开发者ID:BmanGames,项目名称:Toontown-Level-Editor,代码行数:10,代码来源:test_minidom.py


示例10: testRemoveAttributeNode

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
            and child.getAttributeNode("spam") is None)

    dom.unlink()
开发者ID:BmanGames,项目名称:Toontown-Level-Editor,代码行数:11,代码来源:test_minidom.py


示例11: testRemoveAttrNS

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()
开发者ID:BmanGames,项目名称:Toontown-Level-Editor,代码行数:12,代码来源:test_minidom.py


示例12: testAddAttr

def testAddAttr():
    dom = Document()
    child = dom.appendChild(dom.createElement("abc"))

    child.setAttribute("def", "ghi")
    confirm(child.getAttribute("def") == "ghi")
    confirm(child.attributes["def"].value == "ghi")

    child.setAttribute("jkl", "mno")
    confirm(child.getAttribute("jkl") == "mno")
    confirm(child.attributes["jkl"].value == "mno")

    confirm(len(child.attributes) == 2)

    child.setAttribute("def", "newval")
    confirm(child.getAttribute("def") == "newval")
    confirm(child.attributes["def"].value == "newval")

    confirm(len(child.attributes) == 2)
    dom.unlink()
开发者ID:BmanGames,项目名称:Toontown-Level-Editor,代码行数:20,代码来源:test_minidom.py


示例13: range

	
	for obj in objs:
	    temp=string.split(obj.getAttribute("url"), "/")
    	    inc_file_simple=temp[len(temp)-1]
	    
	    temp1=string.split(self.svgFile, "/")
	    real_path=""
	    for i in range (0, len(temp1)-1):
		real_path+="/"+temp1[i]
	    #print "real_path="+real_path
	    inc_file=str(real_path)+"/"+str(inc_file_simple)
	    try:
		doc1=FromXmlFile(inc_file)
		dom1=doc1.documentElement
		includedNode=doc.importNode(dom1,1)
		dom.appendChild(includedNode)
	    except Exception, msg:
		print "MultipleSVG() WARNING: невозможно обработать файл ", inc_file, "[", msg, "]"

	    print "HEREEEEEEEEEEE234324"    
	    
	    
	    # скопировать подинклуживаемые файлы в новый проект
	    try:
		
		f1=open(self.resultPath+"/svg/"+inc_file_simple, 'w')
		Print (doc1, f1, 'utf-8')
		f1.close()
	    except Exception, e:
		print "ERROR. generator.py::MultipleSVG(): Ошибка во время попытки записи файла "+self.resultPath+"/svg/"+inc_file_simple
	
开发者ID:boris-r-v,项目名称:ArmDsp-Generator,代码行数:29,代码来源:generator.py


示例14: testElement

def testElement():
    dom = Document()
    dom.appendChild(dom.createElement("abc"))
    confirm(dom.documentElement)
    dom.unlink()
开发者ID:BmanGames,项目名称:Toontown-Level-Editor,代码行数:5,代码来源:test_minidom.py


示例15: testNonZero

def testNonZero():
    dom = parse(tstfile)
    confirm(dom)# should not be zero
    dom.appendChild(dom.createComment("foo"))
    confirm(not dom.childNodes[-1].childNodes)
    dom.unlink()
开发者ID:BmanGames,项目名称:Toontown-Level-Editor,代码行数:6,代码来源:test_minidom.py


示例16: testAttributeRepr

def testAttributeRepr():
    dom = Document()
    el = dom.appendChild(dom.createElement(u"abc"))
    node = el.setAttribute("abc", "def")
    confirm(str(node) == repr(node))
    dom.unlink()
开发者ID:BmanGames,项目名称:Toontown-Level-Editor,代码行数:6,代码来源:test_minidom.py


示例17: saveAll

    def saveAll(self):

	open(self.resultsPath+"/impulses.diag.xml", 'w').write(self.impCont)
	
	open(self.resultsPath+"/diag.xml", 'w').write(self.diagCont)

	diagButtons=open(self.templatePath+"/diag.buttons.xml", 'r').read()
	open(self.resultsPath+"/diag.buttons.xml", 'w').write(diagButtons)

	open(self.resultsPath+"/diag-tests.xml", 'w').write(self.umvTestsCont)

	open(self.resultsPath+"/impulses.diag-tests.xml", 'w').write(self.umvTestsImpCont)
	
	self.background()	
	
	file=open("../svg/diag/"+self.resultsPath+"/full.svg", 'w')
	Print(self.fullDoc, file, "utf-8")
	file.close()
	    
	


	# Записать эти файлы в storyall.xml
	try:
	    doc = FromXmlFile(self.resultsPath+"/storyall.xml")
	    Print (doc)
	    dom = doc.documentElement
	    
	    inc = doc.createElement("include")
	    inc.setAttribute("url", "diag-tests.xml")
	    isIncAlready=False
	    incs = dom.getElementsByTagName("include")
	    for i in incs:
		if i.getAttribute("url")==inc.getAttribute("url"):
		    isIncAlready=True
		    break
	    if not isIncAlready:
		dom.appendChild(inc)	
		dom.appendChild(doc.createTextNode("\n"))
	
	    inc = doc.createElement("include")
	    inc.setAttribute("url", "diag.xml")
	    isIncAlready=False
	    incs = dom.getElementsByTagName("include")
	    for i in incs:
		if i.getAttribute("url")==inc.getAttribute("url"):
		    isIncAlready=True
		    break
	    if not isIncAlready:
		dom.appendChild(inc)	
		dom.appendChild(doc.createTextNode("\n"))
	    	
	    inc = doc.createElement("include")
	    inc.setAttribute("url", "diag.buttons.xml")
	    isIncAlready=False
	    incs = dom.getElementsByTagName("include")
	    for i in incs:
		if i.getAttribute("url")==inc.getAttribute("url"):
		    isIncAlready=True
		    break
	    if not isIncAlready:
		dom.appendChild(inc)	
		dom.appendChild(doc.createTextNode("\n"))
	
	    f=open(self.resultsPath+"/storyall.xml", 'w')
	    Print(doc, f, "utf-8")
	
	except Exception, msg:
	    print "Diag::saveAll(): EXCEPTION (while writing to 'storyall.xml'):", msg
开发者ID:boris-r-v,项目名称:ArmDsp-Generator,代码行数:69,代码来源:diag.py


示例18: FromXmlFile

	# Записать эти файлы в ts.xml
	try:
	    doc = FromXmlFile("ts.xml")
	    Print (doc)
	    dom = doc.documentElement

	    inc = doc.createElement("include")
	    inc.setAttribute("url", "impulses.maket.xml")
	    isIncAlready=False
	    incs = dom.getElementsByTagName("include")
	    for i in incs:
		if i.getAttribute("url")==inc.getAttribute("url"):
		    isIncAlready=True
		    break
	    if not isIncAlready:
		dom.appendChild(inc)
		dom.appendChild(doc.createTextNode("\n"))

	    f=open("ts.xml", 'w')
	    Print(doc, f, "utf-8")

	except Exception, msg:
	    print "Maket::include(): EXCEPTION (while writing to 'ts.xml'):", msg





    def saveFiles(self):
    
	TSseller = seller.TSandTUseller(self.maxImpulses, ".last.ts")
开发者ID:boris-r-v,项目名称:ArmDsp-Generator,代码行数:31,代码来源:maket.py



注:本文中的xml.dom.appendChild函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python dom.createElement函数代码示例发布时间:2022-05-26
下一篇:
Python xmipp.MetaData类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap