当前位置: 首页>>代码示例>>Python>>正文


Python Element.appendChild方法代码示例

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


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

示例1: test_insertPrevNextText

# 需要导入模块: from xml.dom.minidom import Element [as 别名]
# 或者: from xml.dom.minidom.Element import appendChild [as 别名]
    def test_insertPrevNextText(self):
        """
        L{insertPrevNextLinks} appends a text node with the title of the
        previous slide to each node with a I{previous} class and the title of
        the next slide to each node with a I{next} class.
        """
        next = Element('span')
        next.setAttribute('class', 'next')
        container = Element('div')
        container.appendChild(next)
        slideWithNext = HTMLSlide(container, 'first', 0)

        previous = Element('span')
        previous.setAttribute('class', 'previous')
        container = Element('div')
        container.appendChild(previous)
        slideWithPrevious = HTMLSlide(container, 'second', 1)

        insertPrevNextLinks(
            [slideWithNext, slideWithPrevious], None, None)

        self.assertEqual(
            next.toxml(), '<span class="next">second</span>')
        self.assertEqual(
            previous.toxml(), '<span class="previous">first</span>')
开发者ID:AlexanderHerlan,项目名称:syncpy,代码行数:27,代码来源:test_slides.py

示例2: get

# 需要导入模块: from xml.dom.minidom import Element [as 别名]
# 或者: from xml.dom.minidom.Element import appendChild [as 别名]
    def get(self, *args):
        self.response.headers['Content-Type'] = "application/rss+xml"

        items = self.getItems(*args)

        itemElems = []
        for item in items:
            itemElem = Element("item")
            self._appendElementWithTextNode(itemElem, "title", item.title)
            self._appendElementWithTextNode(itemElem, "link", item.link)
            self._appendElementWithTextNode(itemElem, "description", item.description)
            self._appendElementWithTextNode(itemElem, "guid", item.link)
            if item.subPlaceFeedLink:
                self._appendElementWithTextNode(itemElem, "sharkattackdata:subPlaceFeedLink", item.subPlaceFeedLink)
            if item.attackFeedLink:
                self._appendElementWithTextNode(itemElem, "sharkattackdata:attackFeedLink", item.attackFeedLink)

            itemElems.append(itemElem)

        # Need to make channel element after the generator returned by getItems has been iterated.
        channelElem = Element("channel")
        self._appendElementWithTextNode(channelElem, "title", self._feedTitle)
        self._appendElementWithTextNode(channelElem, "link", self._feedLink)
        self._appendElementWithTextNode(channelElem, "description", self._feedDescription)

        for itemElem in itemElems:
            channelElem.appendChild(itemElem)

        responseText = """<?xml version="1.0"?>
<rss version="2.0" xmlns:sharkattackdata="http://sharkattackdata.com/rss/modules/1.0/">
%s
</rss>
""" % (channelElem.toprettyxml())
        self.response.out.write(responseText)
开发者ID:ikarajas,项目名称:sharkattackdata,代码行数:36,代码来源:rssfeeds.py

示例3: xml_encode

# 需要导入模块: from xml.dom.minidom import Element [as 别名]
# 或者: from xml.dom.minidom.Element import appendChild [as 别名]
 def xml_encode(self, text):
     from xml.dom.minidom import Text, Element
     t = Text()
     t.data = text
     e = Element('x')
     e.appendChild(t)
     return e.toxml()[3:-4]
开发者ID:kbriggs,项目名称:gedit-xml-codec,代码行数:9,代码来源:xmlcodec.py

示例4: node2xml

# 需要导入模块: from xml.dom.minidom import Element [as 别名]
# 或者: from xml.dom.minidom.Element import appendChild [as 别名]
def node2xml(node):
    """Takes in a node object and returns an XML object for that node"""
    ele = Element("node")
    for k, v in node.attrs.items():
        ele.setAttribute(k, v)
    for k, v in node.tags.items():
        ele.appendChild(tag2xml(k, v))
    return ele
开发者ID:h4ck3rm1k3,项目名称:pyxbot,代码行数:10,代码来源:obj2xml.py

示例5: createNode

# 需要导入模块: from xml.dom.minidom import Element [as 别名]
# 或者: from xml.dom.minidom.Element import appendChild [as 别名]
 def createNode(root, nodeName, nodeText):
     """ Add an element node with nodeText to the 'root' element
     """
     from xml.dom.minidom import Element, Text
     ele = Element(nodeName)
     text = Text()
     text.data = nodeText
     ele.appendChild(text)
     root.appendChild(ele)
开发者ID:iesugrace,项目名称:log-with-git,代码行数:11,代码来源:xmlstorage.py

示例6: set_text

# 需要导入模块: from xml.dom.minidom import Element [as 别名]
# 或者: from xml.dom.minidom.Element import appendChild [as 别名]
def set_text(node: Element, text):
    dom = node.ownerDocument

    for child in node.childNodes:
        if child.nodeType == Node.TEXT_NODE:
            node.removeChild(child)

    text_node = dom.createTextNode(text)
    text_node.nodeValue = text
    node.appendChild(text_node)
开发者ID:nikhildamle,项目名称:docx-templater,代码行数:12,代码来源:xml_helper.py

示例7: set_run_text

# 需要导入模块: from xml.dom.minidom import Element [as 别名]
# 或者: from xml.dom.minidom.Element import appendChild [as 别名]
def set_run_text(run: Element, text: str):
    dom = run.ownerDocument

    if run_contains_text(run):
        text_element = run.getElementsByTagNameNS(_namespaces['w'], 't')[0]
        set_text(text_element, text)
    else:
        text_element = dom.createElementNS(_namespaces['w'], 'w:t')
        set_text(text_element, text)
        run.appendChild(text_element)
开发者ID:nikhildamle,项目名称:docx-templater,代码行数:12,代码来源:docx_helper.py

示例8: toDom

# 需要导入模块: from xml.dom.minidom import Element [as 别名]
# 或者: from xml.dom.minidom.Element import appendChild [as 别名]
	def toDom(self):
		r = Element("enum")
		r.setAttribute("name",self.prefix[:-1])
		if self.enumdict is None:
			return r
		for k in sorted(self.enumdict.keys()):
			i = Element("value")
			i.setAttribute("id",str(k))
			i.setAttribute("name",self.enumdict[k])
			r.appendChild(i)
		return r
开发者ID:magwas,项目名称:gamsrv,代码行数:13,代码来源:enumtype.py

示例9: relation2xml

# 需要导入模块: from xml.dom.minidom import Element [as 别名]
# 或者: from xml.dom.minidom.Element import appendChild [as 别名]
def relation2xml(relation):
    ele = Element("relation")
    for k, v in relation.attrs.items():
        ele.setAttribute(k, v)
    for member in relation.members:
        ele = Element("member")
        for k, v in member.items():
            ele.setAttribute(k, v)
    for k, v in relation.tags.items():
        ele.appendChild(tag2xml(k, v))
    return ele
开发者ID:h4ck3rm1k3,项目名称:pyxbot,代码行数:13,代码来源:obj2xml.py

示例10: appendChild

# 需要导入模块: from xml.dom.minidom import Element [as 别名]
# 或者: from xml.dom.minidom.Element import appendChild [as 别名]
 def appendChild(self, node):
     if hasattr(node, 'allowNoSvgChildNode'):
         if not self.allowAllSvgNodesAsChildNodes:
             if not (node.svgNodeType in self._allowedSvgChildNodes):
                 raise HierarchyRequestErr(
                     "%s cannot be child of %s" % (repr(node), repr(self)))
             else:
                 Element.appendChild(self, node)
     Element.appendChild(self, node)
         
         
开发者ID:danrg,项目名称:RGT-tool,代码行数:11,代码来源:basicSvgNode.py

示例11: way2xml

# 需要导入模块: from xml.dom.minidom import Element [as 别名]
# 或者: from xml.dom.minidom.Element import appendChild [as 别名]
def way2xml(way):
    ele = Element('way')
    for k,v in way.attrs.items():
        ele.setAttribute(k,v)
    for ref in way.nodes:
        nd = Element('nd')
        nd.setAtrribute('ref', ref)
        ele.appendChild(nd)
    for k,v in way.tags.items():
        ele.appendChild(tags2xml(k,v))
    return ele
开发者ID:emacsen,项目名称:pyxbot,代码行数:13,代码来源:obj2xml.py

示例12: way2xml

# 需要导入模块: from xml.dom.minidom import Element [as 别名]
# 或者: from xml.dom.minidom.Element import appendChild [as 别名]
def way2xml(way):
    ele = Element("way")
    for k, v in way.attrs.items():
        ele.setAttribute(k, v)
    for ref in way.nodes:
        nd = Element("nd")
        nd.setAttribute("ref", ref)
        ele.appendChild(nd)
    for k, v in way.tags.items():
        ele.appendChild(tag2xml(k, v))
    return ele
开发者ID:h4ck3rm1k3,项目名称:pyxbot,代码行数:13,代码来源:obj2xml.py

示例13: test_code

# 需要导入模块: from xml.dom.minidom import Element [as 别名]
# 或者: from xml.dom.minidom.Element import appendChild [as 别名]
    def test_code(self):
        """
        L{TexiSpitter.visitNode} emits a C{@code} block when it encounters a
        I{code} element.
        """
        codeElement = Element('code')
        text = Text()
        text.data = u'print'
        codeElement.appendChild(text)

        self.spitter.visitNode(codeElement)
        self.assertEqual(''.join(self.output), "@code{print}")
开发者ID:0004c,项目名称:VTK,代码行数:14,代码来源:test_texi.py

示例14: test_title

# 需要导入模块: from xml.dom.minidom import Element [as 别名]
# 或者: from xml.dom.minidom.Element import appendChild [as 别名]
    def test_title(self):
        """
        L{TexiSpitter.visitNode} emits I{@node} and I{@section} blocks when it
        encounters a I{title} element.
        """
        titleElement = Element('title')
        text = Text()
        text.data = u'bar'
        titleElement.appendChild(text)

        self.spitter.visitNode(titleElement)
        self.assertEqual(''.join(self.output), '@node bar\[email protected] bar\n')
开发者ID:0004c,项目名称:VTK,代码行数:14,代码来源:test_texi.py

示例15: test_pre

# 需要导入模块: from xml.dom.minidom import Element [as 别名]
# 或者: from xml.dom.minidom.Element import appendChild [as 别名]
    def test_pre(self):
        """
        L{TexiSpitter.visitNode} emits a verbatim block when it encounters a
        I{pre} element.
        """
        preElement = Element('pre')
        text = Text()
        text.data = u'foo'
        preElement.appendChild(text)

        self.spitter.visitNode(preElement)
        self.assertEqual(''.join(self.output),
            '@verbatim\nfoo\[email protected] verbatim\n')
开发者ID:0004c,项目名称:VTK,代码行数:15,代码来源:test_texi.py


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