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


Python minidom.Text方法代码示例

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


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

示例1: character_data_handler_cdata

# 需要导入模块: from xml.dom import minidom [as 别名]
# 或者: from xml.dom.minidom import Text [as 别名]
def character_data_handler_cdata(self, data):
        childNodes = self.curNode.childNodes
        if self._cdata:
            if (  self._cdata_continue
                  and childNodes[-1].nodeType == CDATA_SECTION_NODE):
                childNodes[-1].appendData(data)
                return
            node = self.document.createCDATASection(data)
            self._cdata_continue = True
        elif childNodes and childNodes[-1].nodeType == TEXT_NODE:
            node = childNodes[-1]
            value = node.data + data
            node.data = value
            return
        else:
            node = minidom.Text()
            node.data = data
            node.ownerDocument = self.document
        _append_child(self.curNode, node) 
开发者ID:war-and-code,项目名称:jawfish,代码行数:21,代码来源:expatbuilder.py

示例2: character_data_handler_cdata

# 需要导入模块: from xml.dom import minidom [as 别名]
# 或者: from xml.dom.minidom import Text [as 别名]
def character_data_handler_cdata(self, data):
        childNodes = self.curNode.childNodes
        if self._cdata:
            if (  self._cdata_continue
                  and childNodes[-1].nodeType == CDATA_SECTION_NODE):
                childNodes[-1].appendData(data)
                return
            node = self.document.createCDATASection(data)
            self._cdata_continue = True
        elif childNodes and childNodes[-1].nodeType == TEXT_NODE:
            node = childNodes[-1]
            value = node.data + data
            d = node.__dict__
            d['data'] = d['nodeValue'] = value
            return
        else:
            node = minidom.Text()
            d = node.__dict__
            d['data'] = d['nodeValue'] = data
            d['ownerDocument'] = self.document
        _append_child(self.curNode, node) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:23,代码来源:expatbuilder.py

示例3: render_GET

# 需要导入模块: from xml.dom import minidom [as 别名]
# 或者: from xml.dom.minidom import Text [as 别名]
def render_GET(self, request):
        """
        Render as HTML a listing of all known users with links to their
        personal resources.
        """
        listing = Element('ul')
        for link, text in self._users():
            linkElement = Element('a')
            linkElement.setAttribute('href', link + '/')
            textNode = Text()
            textNode.data = text
            linkElement.appendChild(textNode)
            item = Element('li')
            item.appendChild(linkElement)
            listing.appendChild(item)
        return self.template % {'users': listing.toxml()} 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:18,代码来源:distrib.py

示例4: insertPrevNextLinks

# 需要导入模块: from xml.dom import minidom [as 别名]
# 或者: from xml.dom.minidom import Text [as 别名]
def insertPrevNextLinks(slides, filename, ext):
    for slide in slides:
        for name, offset in (("previous", -1), ("next", +1)):
            if (slide.pos > 0 and name == "previous") or \
               (slide.pos < len(slides)-1 and name == "next"):
                for node in domhelpers.findElementsWithAttribute(slide.dom, "class", name):
                    if node.tagName == 'a':
                        node.setAttribute('href', '%s-%d%s'
                                          % (filename[0], slide.pos+offset, ext))
                    else:
                        text = dom.Text()
                        text.data = slides[slide.pos+offset].title
                        node.appendChild(text)
            else:
                for node in domhelpers.findElementsWithAttribute(slide.dom, "class", name):
                    pos = 0
                    for child in node.parentNode.childNodes:
                        if child is node:
                            del node.parentNode.childNodes[pos]
                            break
                        pos += 1 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:23,代码来源:slides.py

示例5: addMtime

# 需要导入模块: from xml.dom import minidom [as 别名]
# 或者: from xml.dom.minidom import Text [as 别名]
def addMtime(document, fullpath):
    """
    Set the last modified time of the given document.

    @type document: A DOM Node or Document
    @param document: The output template which defines the presentation of the
    last modified time.

    @type fullpath: C{str}
    @param fullpath: The file name from which to take the last modified time.

    @return: C{None}
    """
    for node in domhelpers.findElementsWithAttribute(document, "class","mtime"):
        txt = dom.Text()
        txt.data = time.ctime(os.path.getmtime(fullpath))
        node.appendChild(txt) 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:19,代码来源:tree.py

示例6: _makeLineNumbers

# 需要导入模块: from xml.dom import minidom [as 别名]
# 或者: from xml.dom.minidom import Text [as 别名]
def _makeLineNumbers(howMany):
    """
    Return an element which will render line numbers for a source listing.

    @param howMany: The number of lines in the source listing.
    @type howMany: C{int}

    @return: An L{dom.Element} which can be added to the document before
        the source listing to add line numbers to it.
    """
    # Figure out how many digits wide the widest line number label will be.
    width = len(str(howMany))

    # Render all the line labels with appropriate padding
    labels = ['%*d' % (width, i) for i in range(1, howMany + 1)]

    # Create a p element with the right style containing the labels
    p = dom.Element('p')
    p.setAttribute('class', 'py-linenumber')
    t = dom.Text()
    t.data = '\n'.join(labels) + '\n'
    p.appendChild(t)
    return p 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:25,代码来源:tree.py

示例7: setVersion

# 需要导入模块: from xml.dom import minidom [as 别名]
# 或者: from xml.dom.minidom import Text [as 别名]
def setVersion(template, version):
    """
    Add a version indicator to the given template.

    @type template: A DOM Node or Document
    @param template: The output template which defines the presentation of the
    version information.

    @type version: C{str}
    @param version: The version string to add to the template.

    @return: C{None}
    """
    for node in domhelpers.findElementsWithAttribute(template, "class",
                                                               "version"):
        text = dom.Text()
        text.data = version
        node.appendChild(text) 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:20,代码来源:tree.py

示例8: test_setTitle

# 需要导入模块: from xml.dom import minidom [as 别名]
# 或者: from xml.dom.minidom import Text [as 别名]
def test_setTitle(self):
        """
        L{tree.setTitle} inserts the given title into the first I{title}
        element and the first element with the I{title} class in the given
        template.
        """
        parent = dom.Element('div')
        firstTitle = dom.Element('title')
        parent.appendChild(firstTitle)
        secondTitle = dom.Element('span')
        secondTitle.setAttribute('class', 'title')
        parent.appendChild(secondTitle)

        titleNodes = [dom.Text()]
        # minidom has issues with cloning documentless-nodes.  See Python issue
        # 4851.
        titleNodes[0].ownerDocument = dom.Document()
        titleNodes[0].data = 'foo bar'

        tree.setTitle(parent, titleNodes, None)
        self.assertEqual(firstTitle.toxml(), '<title>foo bar</title>')
        self.assertEqual(
            secondTitle.toxml(), '<span class="title">foo bar</span>') 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:25,代码来源:test_lore.py

示例9: test_setTitleWithChapter

# 需要导入模块: from xml.dom import minidom [as 别名]
# 或者: from xml.dom.minidom import Text [as 别名]
def test_setTitleWithChapter(self):
        """
        L{tree.setTitle} includes a chapter number if it is passed one.
        """
        document = dom.Document()

        parent = dom.Element('div')
        parent.ownerDocument = document

        title = dom.Element('title')
        parent.appendChild(title)

        titleNodes = [dom.Text()]
        titleNodes[0].ownerDocument = document
        titleNodes[0].data = 'foo bar'

        # Oh yea.  The numberer has to agree to put the chapter number in, too.
        numberer.setNumberSections(True)

        tree.setTitle(parent, titleNodes, '13')
        self.assertEqual(title.toxml(), '<title>13. foo bar</title>') 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:23,代码来源:test_lore.py

示例10: test_makeLineNumbers

# 需要导入模块: from xml.dom import minidom [as 别名]
# 或者: from xml.dom.minidom import Text [as 别名]
def test_makeLineNumbers(self):
        """
        L{tree._makeLineNumbers} takes an integer and returns a I{p} tag with
        that number of line numbers in it.
        """
        numbers = tree._makeLineNumbers(1)
        self.assertEqual(numbers.tagName, 'p')
        self.assertEqual(numbers.getAttribute('class'), 'py-linenumber')
        self.assertIsInstance(numbers.firstChild, dom.Text)
        self.assertEqual(numbers.firstChild.nodeValue, '1\n')

        numbers = tree._makeLineNumbers(10)
        self.assertEqual(numbers.tagName, 'p')
        self.assertEqual(numbers.getAttribute('class'), 'py-linenumber')
        self.assertIsInstance(numbers.firstChild, dom.Text)
        self.assertEqual(
            numbers.firstChild.nodeValue,
            ' 1\n 2\n 3\n 4\n 5\n'
            ' 6\n 7\n 8\n 9\n10\n') 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:21,代码来源:test_lore.py

示例11: test_fontifyPythonNode

# 需要导入模块: from xml.dom import minidom [as 别名]
# 或者: from xml.dom.minidom import Text [as 别名]
def test_fontifyPythonNode(self):
        """
        L{tree.fontifyPythonNode} accepts a text node and replaces it in its
        parent with a syntax colored and line numbered version of the Python
        source it contains.
        """
        parent = dom.Element('div')
        source = dom.Text()
        source.data = 'def foo():\n    pass\n'
        parent.appendChild(source)

        tree.fontifyPythonNode(source)

        expected = """\
<div><pre class="python"><p class="py-linenumber">1
2
</p><span class="py-src-keyword">def</span> <span class="py-src-identifier">foo</span>():
    <span class="py-src-keyword">pass</span>
</pre></div>"""

        self.assertEqual(parent.toxml(), expected) 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:23,代码来源:test_lore.py

示例12: test_fixAPI

# 需要导入模块: from xml.dom import minidom [as 别名]
# 或者: from xml.dom.minidom import Text [as 别名]
def test_fixAPI(self):
        """
        The element passed to L{tree.fixAPI} has all of its children with the
        I{API} class rewritten to contain links to the API which is referred to
        by the text they contain.
        """
        parent = dom.Element('div')
        link = dom.Element('span')
        link.setAttribute('class', 'API')
        text = dom.Text()
        text.data = 'foo'
        link.appendChild(text)
        parent.appendChild(link)

        tree.fixAPI(parent, 'http://example.com/%s')
        self.assertEqual(
            parent.toxml(),
            '<div><span class="API">'
            '<a href="http://example.com/foo" title="foo">foo</a>'
            '</span></div>') 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:22,代码来源:test_lore.py

示例13: test_nonASCIIData

# 需要导入模块: from xml.dom import minidom [as 别名]
# 或者: from xml.dom.minidom import Text [as 别名]
def test_nonASCIIData(self):
        """
        A document which contains non-ascii characters is serialized to a
        file using UTF-8.
        """
        document = dom.Document()
        parent = dom.Element('foo')
        text = dom.Text()
        text.data = u'\N{SNOWMAN}'
        parent.appendChild(text)
        document.appendChild(parent)
        outFile = self.mktemp()
        tree._writeDocument(outFile, document)
        self.assertXMLEqual(
            FilePath(outFile).getContent(),
            u'<foo>\N{SNOWMAN}</foo>'.encode('utf-8')) 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:18,代码来源:test_lore.py

示例14: test_li

# 需要导入模块: from xml.dom import minidom [as 别名]
# 或者: from xml.dom.minidom import Text [as 别名]
def test_li(self):
        """
        L{DocbookSpitter} wraps any non-I{p} elements found intside any I{li}
        elements with I{p} elements.
        """
        output = []
        spitter = DocbookSpitter(output.append)

        li = Element('li')
        li.appendChild(Element('p'))
        text = Text()
        text.data = 'foo bar'
        li.appendChild(text)

        spitter.visitNode(li)
        self.assertEqual(
            ''.join(output),
            '<listitem><para></para><para>foo bar</para></listitem>') 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:20,代码来源:test_docbook.py

示例15: character_data_handler

# 需要导入模块: from xml.dom import minidom [as 别名]
# 或者: from xml.dom.minidom import Text [as 别名]
def character_data_handler(self, data):
        childNodes = self.curNode.childNodes
        if childNodes and childNodes[-1].nodeType == TEXT_NODE:
            node = childNodes[-1]
            node.data = node.data + data
            return
        node = minidom.Text()
        node.data = node.data + data
        node.ownerDocument = self.document
        _append_child(self.curNode, node) 
开发者ID:war-and-code,项目名称:jawfish,代码行数:12,代码来源:expatbuilder.py


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