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

Python dom.createElement函数代码示例

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

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



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

示例1: add_wl_links

        def add_wl_links(paragraph, text):
            words = text.split()
            punctuation = '.,!"\''

            current = []
            for i, word in enumerate(words):
                if not word.startswith('wl_'):
                    current += [word]
                    continue

                ending = ''
                if not word[-1].isalpha() and word[-1] in punctuation:
                    ending = word[-1]
                    word = word[:-1]

                t = protocol.lookup(word)
                if t is None:
                    current += [word + ending]
                else:
                    add_text_node(p, current, len(current) > 0)
                    current = []

                    a = dom.createElement('a')
                    a.setAttribute('href', t.get_url())
                    add_text_node(a, [word])
                    p.appendChild(a)

                    current += [ending]

            add_text_node(p, current)
开发者ID:jonnylamb,项目名称:wayland-docs,代码行数:30,代码来源:protocolparser.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: _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


示例4: 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


示例5: 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


示例6: 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


示例7: testInsertBefore

def testInsertBefore():
    dom = parseString("<doc><foo/></doc>")
    root = dom.documentElement
    elem = root.childNodes[0]
    nelem = dom.createElement("element")
    root.insertBefore(nelem, elem)
    confirm(len(root.childNodes) == 2
            and root.childNodes.length == 2
            and root.childNodes[0] is nelem
            and root.childNodes.item(0) is nelem
            and root.childNodes[1] is elem
            and root.childNodes.item(1) is elem
            and root.firstChild is nelem
            and root.lastChild is elem
            and root.toxml() == "<doc><element/><foo/></doc>"
            , "testInsertBefore -- node properly placed in tree")
    nelem = dom.createElement("element")
    root.insertBefore(nelem, None)
    confirm(len(root.childNodes) == 3
            and root.childNodes.length == 3
            and root.childNodes[1] is elem
            and root.childNodes.item(1) is elem
            and root.childNodes[2] is nelem
            and root.childNodes.item(2) is nelem
            and root.lastChild is nelem
            and nelem.previousSibling is elem
            and root.toxml() == "<doc><element/><foo/><element/></doc>"
            , "testInsertBefore -- node properly placed in tree")
    nelem2 = dom.createElement("bar")
    root.insertBefore(nelem2, nelem)
    confirm(len(root.childNodes) == 4
            and root.childNodes.length == 4
            and root.childNodes[2] is nelem2
            and root.childNodes.item(2) is nelem2
            and root.childNodes[3] is nelem
            and root.childNodes.item(3) is nelem
            and nelem2.nextSibling is nelem
            and nelem.previousSibling is nelem2
            and root.toxml() == "<doc><element/><foo/><bar/><element/></doc>"
            , "testInsertBefore -- node properly placed in tree")
    dom.unlink()
开发者ID:BmanGames,项目名称:Toontown-Level-Editor,代码行数:41,代码来源:test_minidom.py


示例8: construct_node

def construct_node(dom, styles):
    styles = styles[:]
    styles.reverse()
    root = None
    last = None
    for s in styles:
        n = dom.createElement(s['tag'])
        n.attributes = s['attributes']
        if not root:
            root = n
        if last:
            last.appendChild(n)
        last = n
    return root, n
开发者ID:mivanov,项目名称:editkit,代码行数:14,代码来源:html.py


示例9: admin_export_all_compos

def admin_export_all_compos(request):
    if not request.user.has_perm("compo.admin"):
        return HttpResponseNotFound()

    party = get_party(request)
    dom = xml.dom.minidom.getDOMImplementation().createDocument(None, "tag", None)
    compos = dom.createElement("compos")
    for compo in Competition.objects.filter(party=party):
        compos.appendChild(compo.export_xml(compo.results_public or request.user.has_perm("compo.count_votes")))

    xmldata = generate_xml(compos)
    resp = HttpResponse(content_type="text/xml")
    resp["Content-Disposition"] = 'attachment; filename="%s_compos_all_export.xml"' % party.slug.lower()

    resp.write(xmldata)
    return resp
开发者ID:Barro,项目名称:PMS,代码行数:16,代码来源:views.py


示例10: testNamedNodeMapSetItem

def testNamedNodeMapSetItem():
    dom = Document()
    elem = dom.createElement('element')
    attrs = elem.attributes
    attrs["foo"] = "bar"
    a = attrs.item(0)
    confirm(a.ownerDocument is dom,
            "NamedNodeMap.__setitem__() sets ownerDocument")
    confirm(a.ownerElement is elem,
            "NamedNodeMap.__setitem__() sets ownerElement")
    confirm(a.value == "bar",
            "NamedNodeMap.__setitem__() sets value")
    confirm(a.nodeValue == "bar",
            "NamedNodeMap.__setitem__() sets nodeValue")
    elem.unlink()
    dom.unlink()
开发者ID:BmanGames,项目名称:Toontown-Level-Editor,代码行数:16,代码来源:test_minidom.py


示例11: 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


示例12: find_own_dom_element

    def find_own_dom_element(self):
        """find_own_dom_element() -> (DOM, Node)

        Opens the startup DOM, looks for the element that belongs to the package,
        and returns DOM and node. Creates a new one if element is not there.

        """
        dom = get_vistrails_application().vistrailsStartup.startup_dom()
        doc = dom.documentElement
        packages = enter_named_element(doc, 'packages')
        for package_node in named_elements(packages, 'package'):
            if str(package_node.attributes['name'].value) == self.codepath:
                return (dom, package_node)

        # didn't find anything, create a new node

        package_node = dom.createElement("package")
        package_node.setAttribute('name', self.codepath)
        packages.appendChild(package_node)

        get_vistrails_application().vistrailsStartup.write_startup_dom(dom)
        return (dom, package_node)
开发者ID:CMUSV-VisTrails,项目名称:WorkflowRecommendation,代码行数:22,代码来源:package.py


示例13: testUserData

def testUserData():
    dom = Document()
    n = dom.createElement('e')
    confirm(n.getUserData("foo") is None)
    n.setUserData("foo", None, None)
    confirm(n.getUserData("foo") is None)
    n.setUserData("foo", 12, 12)
    n.setUserData("bar", 13, 13)
    confirm(n.getUserData("foo") == 12)
    confirm(n.getUserData("bar") == 13)
    n.setUserData("foo", None, None)
    confirm(n.getUserData("foo") is None)
    confirm(n.getUserData("bar") == 13)

    handler = UserDataHandler()
    n.setUserData("bar", 12, handler)
    c = n.cloneNode(1)
    confirm(handler.called
            and n.getUserData("bar") is None
            and c.getUserData("bar") == 13)
    n.unlink()
    c.unlink()
    dom.unlink()
开发者ID:BmanGames,项目名称:Toontown-Level-Editor,代码行数:23,代码来源:test_minidom.py


示例14: admin_export_xml

def admin_export_xml(request, compo):
    if not request.user.has_perm("compo.admin"):
        return HttpResponseNotFound()

    party = get_party(request)
    try:
        try:
            compo = Competition.objects.get(slug=compo, party=party)
        except Competition.DoesNotExist:
            raise InvalidCompetition()

    except InvalidCompetition:
        messages.add_message(request, messages.ERROR, "Invalid competition")
        return HttpResponseRedirect(reverse("compo.views.index", args=[request.party]))

    dom = xml.dom.minidom.getDOMImplementation().createDocument(None, "tag", None)
    compos = dom.createElement("compos")
    compos.appendChild(compo.export_xml(compo.results_public or request.user.has_perm("compo.count_votes")))
    xmldata = generate_xml(compos)

    resp = HttpResponse(content_type="text/xml")
    resp["Content-Disposition"] = 'attachment; filename="%s_%s_export.xml"' % (party.slug, compo.name.lower())
    resp.write(xmldata)
    return resp
开发者ID:Barro,项目名称:PMS,代码行数:24,代码来源:views.py


示例15: _get_package_node

    def _get_package_node(self, dom, create):
        doc = dom.documentElement
        packages = enter_named_element(doc, 'packages')
        for package_node in named_elements(packages, 'package'):
            if package_node.attributes['name'].value == self.codepath:
                return package_node, 'enabled'
        oldpackages = enter_named_element(doc, 'disabledpackages')
        for package_node in named_elements(oldpackages, 'package'):
            if package_node.attributes['name'].value == self.codepath:
                return package_node, 'disabled'

        if create is None:
            return None, None
        else:
            package_node = dom.createElement('package')
            package_node.setAttribute('name', self.codepath)
            if create == 'enabled':
                packages.appendChild(package_node)
            elif create == 'disabled':
                oldpackages.appendChild(package_node)
            else:
                raise ValueError
            get_vistrails_application().vistrailsStartup.write_startup_dom(dom)
            return package_node, create
开发者ID:lumig242,项目名称:VisTrailsRecommendation,代码行数:24,代码来源:package.py


示例16: admin_export_xsl

def admin_export_xsl(request, compo):
    if not request.user.has_perm("compo.admin"):
        return HttpResponseNotFound()

    party = get_party(request)
    try:
        try:
            compo = Competition.objects.get(slug=compo, party=party)
        except Competition.DoesNotExist:
            raise InvalidCompetition()

    except InvalidCompetition:
        messages.add_message(request, messages.ERROR, "Invalid competition")
        return HttpResponseRedirect(reverse("compo.views.index", args=[request.party]))

    if request.method == "POST":
        dom = xml.dom.minidom.getDOMImplementation().createDocument(None, "tag", None)
        compos = dom.createElement("compos")
        compos.appendChild(compo.export_xml(compo.results_public or request.user.has_perm("compo.count_votes")))
        xmldata = generate_xml(compos)

        xsl = ""
        uploadedFile = request.FILES["xslpacket"]
        for c in uploadedFile.chunks():
            xsl += c

        result = transform_xsl(xsl, xmldata)

        output_type = request.POST.get("output_type", "txt")

        if output_type == "txt":
            return HttpResponse(result.encode("utf-8"), mimetype="text/plain")
        elif output_type == "diploma":
            tmpxsl = tempfile.NamedTemporaryFile(delete=False)
            tmpxsl.write(xsl)
            tmpxsl.close()
            tmpdata = tempfile.NamedTemporaryFile(delete=False)
            tmpdata.write(result.encode("utf-8"))
            tmpdata.close()
            tmpout, tmpoutname = tempfile.mkstemp()
            tmpout.close()

            retcode = subprocess.call(["fop", "-xml", tmpdata.name, "-xsl", tmpxsl.name, "-pdf", tmpoutname])

            os.unlink(tmpxsl.name)
            os.unlink(tmpdata.name)
            if retcode == 0:
                outfile = open(tmpoutname)
                resp = HttpResponse(content_type="application/pdf")
                resp["Content-Disposition"] = 'attachment; filename="%s_%s_diploma_export.pdf"' % (
                    party.slug,
                    compo.name.lower(),
                )
                resp.write(outfile.read())
                outfile.close()
                os.unlink(tmpoutname)
                return resp

        elif output_type == "impress":
            odpfile = tempfile.NamedTemporaryFile(delete=False)
            for c in request.FILES["odppacket"].chunks():
                odpfile.write(c)
            # 			odpfile.close()
            archive = zipfile.ZipFile(odpfile, "a")
            archive.writestr("content.xml", result.encode("utf-8"))
            archive.close()
            result = open(odpfile.name, "r")
            resp = HttpResponse(content_type="application/octet-stream")
            resp["Content-Disposition"] = 'attachment; filename="%s_%s_export.odp"' % (party.slug, compo.name.lower())
            resp.write(result.read())
            return resp

    return HttpResponseNotFound()
开发者ID:Barro,项目名称:PMS,代码行数:73,代码来源:views.py


示例17: open

            copper0 = None
            for g in gNodes:
                if g.getAttribute("id") == "copper1":
                    copper1 = g
                if g.getAttribute("id") == "copper0":
                    copper0 = g

            if copper1:
                continue
                
            if not copper0:
                print "copper0 not found in", svgFilename
                continue
                
            print "adding copper1 to", svgFilename
            copper1 = dom.createElement("g")
            copper1.setAttribute("id", "copper1")
            copper0.parentNode.insertBefore(copper1, copper0)
            copper1.appendChild(copper0)
            outfile = open(svgFilename, 'wb')
            s = dom.toxml("UTF-8")
            # s = re.sub('\s*\n\s*\n', '', s)   # ghosts of removed (and unlinked) nodes seem to generate newlines, so tighten up the xml
            outfile.write(s)
            outfile.flush()
            outfile.close()                        
            
if __name__ == "__main__":
        main()


开发者ID:BrentWilkins,项目名称:fritzing-app,代码行数:28,代码来源:copper1svg.py


示例18: range

        thesis = {}
        # for each column, make the column name the key and the column 
        # content the value of a new thesis dictionary entry 
        for i in range(len(tags)):
            thesis[tags[i]] = row[i].decode('utf-8')

       	theses.append(thesis)

    rowNum +=1 

for thesis in theses:
		#if unititle year equals thesis year:
	for sub in subseries:
		if sub.getElementsByTagName("unittitle")[0].firstChild.nodeValue == thesis["unitdate"]:
			#create c with refid and level <c id="{refid}" level="item">
			c = dom.createElement("c")
			c.attributes["id"] = thesis["refid"]
			c.attributes["level"] = "item"
			sub.appendChild(c)	
			#create did
			did = dom.createElement("did") 
			c.appendChild(did)
			#create unittitle tag
			unittitle = dom.createElement("unittitle")
			did.appendChild(unittitle)
			unittitle.appendChild(dom.createTextNode(thesis["unittitle"]))
			#create langmaterial tag 	
			langmaterial = dom.createElement("langmaterial")
			did.appendChild(langmaterial)
			language = dom.createElement("language")
			language.attributes["langcode"] = "eng"
开发者ID:imclab,项目名称:itp-archive,代码行数:31,代码来源:xml-generator.py


示例19: convert_to_html

    def convert_to_html(self, node):
        protocol = self.get_protocol()
        dom = protocol.document

        lines = [s.strip() for s in getText(node).split('\n')]

        # get rid of rubbish at beginning and end
        while not lines[0]: del lines[0]
        while not lines[-1]: del lines[-1]

        # split lines by empty elements
        paragraphs = [list(group) for k, group in itertools.groupby(lines, bool) if k]

        # remove old text node
        node.removeChild(node.childNodes[0])

        def add_text_node(element, words, padding=False):
            if not words:
                return

            if padding:
                words += ' '

            text = ' '.join(words)
            t = dom.createTextNode(text)
            element.appendChild(t)

        # add anchor tags for stuff we can link to
        def add_wl_links(paragraph, text):
            words = text.split()
            punctuation = '.,!"\''

            current = []
            for i, word in enumerate(words):
                if not word.startswith('wl_'):
                    current += [word]
                    continue

                ending = ''
                if not word[-1].isalpha() and word[-1] in punctuation:
                    ending = word[-1]
                    word = word[:-1]

                t = protocol.lookup(word)
                if t is None:
                    current += [word + ending]
                else:
                    add_text_node(p, current, len(current) > 0)
                    current = []

                    a = dom.createElement('a')
                    a.setAttribute('href', t.get_url())
                    add_text_node(a, [word])
                    p.appendChild(a)

                    current += [ending]

            add_text_node(p, current)

        # add new paragraph nodes
        for text in [' '.join(x) for x in paragraphs]:
            p = dom.createElement('p')
            add_wl_links(p, text)
            node.appendChild(p)

        return node.toxml().encode('ascii', 'xmlcharrefreplace')
开发者ID:jonnylamb,项目名称:wayland-docs,代码行数:66,代码来源:protocolparser.py


示例20: 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



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python dom.getDOMImplementation函数代码示例发布时间:2022-05-26
下一篇:
Python dom.appendChild函数代码示例发布时间: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