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


Python ElementTree.ElementTree方法代码示例

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


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

示例1: unknown_endtag

# 需要导入模块: from elementtree import ElementTree [as 别名]
# 或者: from elementtree.ElementTree import ElementTree [as 别名]
def unknown_endtag(self, tag):
            self.handle_endtag(tag)

##
# ElementTree builder for HTML source code.  This builder converts an
# HTML document or fragment to an ElementTree.
# <p>
# The parser is relatively picky, and requires balanced tags for most
# elements.  However, elements belonging to the following group are
# automatically closed: P, LI, TR, TH, and TD.  In addition, the
# parser automatically inserts end tags immediately after the start
# tag, and ignores any end tags for the following group: IMG, HR,
# META, and LINK.
#
# @keyparam builder Optional builder object.  If omitted, the parser
#     uses the standard <b>elementtree</b> builder.
# @keyparam encoding Optional character encoding, if known.  If omitted,
#     the parser looks for META tags inside the document.  If no tags
#     are found, the parser defaults to ISO-8859-1.  Note that if your
#     document uses a non-ASCII compatible encoding, you must decode
#     the document before parsing. 
开发者ID:alexfeng,项目名称:InternationalizationScript-iOS,代码行数:23,代码来源:pythondoc.py

示例2: writetext

# 需要导入模块: from elementtree import ElementTree [as 别名]
# 或者: from elementtree.ElementTree import ElementTree [as 别名]
def writetext(self, elem, compact=0):
        if len(elem):
            if compact and len(elem) == 1 and elem[0].tag == "p":
                elem = elem[0]
                self.file.write(html_encode(elem.text))
                for e in elem:
                    ET.ElementTree(e).write(self.file)
                self.file.write(html_encode(elem.tail))
            else:
                for e in elem:
                    ET.ElementTree(e).write(self.file)
        elif elem is not None and elem.text:
            if compact:
                self.file.write(html_encode(elem.text))
            else:
                self.file.write("<p>%s</p>\n" % html_encode(elem.text))

    ##
    # Writes an object description (the description text, parameters,
    # return values) etc.
    #
    # @param object The object element.
    # @param summary If true, use summary instead of full description. 
开发者ID:alexfeng,项目名称:InternationalizationScript-iOS,代码行数:25,代码来源:pythondoc.py

示例3: parsefile

# 需要导入模块: from elementtree import ElementTree [as 别名]
# 或者: from elementtree.ElementTree import ElementTree [as 别名]
def parsefile():
    """
    Test parsing from file.

    >>> tree = ElementTree.parse("samples/simple.xml")
    >>> normalize_crlf(tree)
    >>> tree.write(sys.stdout)
    <root>
       <element key="value">text</element>
       <element>text</element>tail
       <empty-element />
    </root>
    >>> tree = ElementTree.parse("samples/simple-ns.xml")
    >>> normalize_crlf(tree)
    >>> tree.write(sys.stdout)
    <ns0:root xmlns:ns0="namespace">
       <ns0:element key="value">text</ns0:element>
       <ns0:element>text</ns0:element>tail
       <ns0:empty-element />
    </ns0:root>
    """ 
开发者ID:seppius-xbmc-repo,项目名称:ru,代码行数:23,代码来源:selftest.py

示例4: parseliteral

# 需要导入模块: from elementtree import ElementTree [as 别名]
# 或者: from elementtree.ElementTree import ElementTree [as 别名]
def parseliteral():
    r"""
    >>> element = ElementTree.XML("<html><body>text</body></html>")
    >>> ElementTree.ElementTree(element).write(sys.stdout)
    <html><body>text</body></html>
    >>> element = ElementTree.fromstring("<html><body>text</body></html>")
    >>> ElementTree.ElementTree(element).write(sys.stdout)
    <html><body>text</body></html>
    >>> print ElementTree.tostring(element)
    <html><body>text</body></html>
    >>> print ElementTree.tostring(element, "ascii")
    <?xml version='1.0' encoding='ascii'?>
    <html><body>text</body></html>
    >>> _, ids = ElementTree.XMLID("<html><body>text</body></html>")
    >>> len(ids)
    0
    >>> _, ids = ElementTree.XMLID("<html><body id='body'>text</body></html>")
    >>> len(ids)
    1
    >>> ids["body"].tag
    'body'
    """ 
开发者ID:seppius-xbmc-repo,项目名称:ru,代码行数:24,代码来源:selftest.py

示例5: entity

# 需要导入模块: from elementtree import ElementTree [as 别名]
# 或者: from elementtree.ElementTree import ElementTree [as 别名]
def entity():
    """
    Test entity handling.

    1) bad entities

    >>> ElementTree.XML("<document>&entity;</document>")
    Traceback (most recent call last):
    ExpatError: undefined entity: line 1, column 10

    >>> ElementTree.XML(ENTITY_XML)
    Traceback (most recent call last):
    ExpatError: undefined entity &entity;: line 5, column 10

    (add more tests here)

    """ 
开发者ID:seppius-xbmc-repo,项目名称:ru,代码行数:19,代码来源:selftest.py

示例6: parse

# 需要导入模块: from elementtree import ElementTree [as 别名]
# 或者: from elementtree.ElementTree import ElementTree [as 别名]
def parse(self, encoding=None, errors='strict', **kwargs):
        """Parses a settings file using ElementTree.
        
        @param encoding: encoding used by settings file
        @type  encoding: string        
        @param errors: Error handling scheme for codec. Same as C{.decode} inbuilt method.
        @type errors: string
        @param kwargs: Keyword arguments passed to L{StandardFormat.fields()}
        @type kwargs: keyword arguments dictionary
        @rtype:   ElementTree._ElementInterface
        @return:  contents of toolbox settings file with a nested structure
        """
        builder = ElementTree.TreeBuilder()
        for mkr, value in self.fields(encoding=encoding, errors=errors, **kwargs):
            # Check whether the first char of the field marker
            # indicates a block start (+) or end (-)
            block=mkr[0]
            if block in ("+", "-"):
                mkr=mkr[1:]
            else:
                block=None
            # Build tree on the basis of block char
            if block == "+":
                builder.start(mkr, {})
                builder.data(value)
            elif block == '-':
                builder.end(mkr)
            else:
                builder.start(mkr, {})
                builder.data(value)
                builder.end(mkr)
        return ElementTree.ElementTree(builder.close()) 
开发者ID:rafasashi,项目名称:razzy-spinner,代码行数:34,代码来源:settings.py

示例7: get_field_marker_hierarchy

# 需要导入模块: from elementtree import ElementTree [as 别名]
# 或者: from elementtree.ElementTree import ElementTree [as 别名]
def get_field_marker_hierarchy(self) :
        # Find root field marker
        root = None
        for fm in self.get_markers() :
            fmmd = self.get_metadata_by_marker(fm)            
            if not fmmd.get_parent_marker() :
                root = fm

        # Build tree for field markers
        builder = ElementTree.TreeBuilder()
        builder.start(root, {})
        self.build_tree(root, builder)
        builder.end(root)
        return ElementTree.ElementTree(builder.close()) 
开发者ID:rafasashi,项目名称:razzy-spinner,代码行数:16,代码来源:settings.py

示例8: create_manifest

# 需要导入模块: from elementtree import ElementTree [as 别名]
# 或者: from elementtree.ElementTree import ElementTree [as 别名]
def create_manifest(self):
        if WhichElementTree == 'lxml':
            root = Element('manifest:manifest',
                nsmap=MANIFEST_NAMESPACE_DICT,
                nsdict=MANIFEST_NAMESPACE_DICT,
                )
        else:
            root = Element('manifest:manifest',
                attrib=MANIFEST_NAMESPACE_ATTRIB,
                nsdict=MANIFEST_NAMESPACE_DICT,
                )
        doc = etree.ElementTree(root)
        SubElement(root, 'manifest:file-entry', attrib={
            'manifest:media-type': self.MIME_TYPE,
            'manifest:full-path': '/',
            }, nsdict=MANNSD)
        SubElement(root, 'manifest:file-entry', attrib={
            'manifest:media-type': 'text/xml',
            'manifest:full-path': 'content.xml',
            }, nsdict=MANNSD)
        SubElement(root, 'manifest:file-entry', attrib={
            'manifest:media-type': 'text/xml',
            'manifest:full-path': 'styles.xml',
            }, nsdict=MANNSD)
        SubElement(root, 'manifest:file-entry', attrib={
            'manifest:media-type': 'text/xml',
            'manifest:full-path': 'settings.xml',
            }, nsdict=MANNSD)
        SubElement(root, 'manifest:file-entry', attrib={
            'manifest:media-type': 'text/xml',
            'manifest:full-path': 'meta.xml',
            }, nsdict=MANNSD)
        s1 = ToString(doc)
        doc = minidom.parseString(s1)
        s1 = doc.toprettyxml('  ')
        return s1 
开发者ID:skarlekar,项目名称:faces,代码行数:38,代码来源:__init__.py

示例9: astext

# 需要导入模块: from elementtree import ElementTree [as 别名]
# 或者: from elementtree.ElementTree import ElementTree [as 别名]
def astext(self):
        root = self.content_tree.getroot()
        et = etree.ElementTree(root)
        s1 = ToString(et)
        return s1 
开发者ID:skarlekar,项目名称:faces,代码行数:7,代码来源:__init__.py

示例10: loadBlissLexicon

# 需要导入模块: from elementtree import ElementTree [as 别名]
# 或者: from elementtree.ElementTree import ElementTree [as 别名]
def loadBlissLexicon(fname):
    from elementtree.ElementTree import ElementTree
    xml = ElementTree(file = gOpenIn(fname))
    pronunciations = pronunciationsFromXmlLexicon(xml)
    result = [ (orth, phon)
               for orth in pronunciations
               if not (orth.startswith('[') and orth.endswith(']'))
               for phon in pronunciations[orth] ]
    result.sort()
    return result 
开发者ID:sequitur-g2p,项目名称:sequitur-g2p,代码行数:12,代码来源:g2p.py

示例11: exportTopicTreeSpecXml

# 需要导入模块: from elementtree import ElementTree [as 别名]
# 或者: from elementtree.ElementTree import ElementTree [as 别名]
def exportTopicTreeSpecXml(moduleName=None, rootTopic=None, bak='bak', moduleDoc=None):
    """
    If rootTopic is None, then pub.getDefaultTopicTreeRoot() is assumed.
    """

    if rootTopic is None:
        from .. import pub
        rootTopic = pub.getDefaultTopicTreeRoot()
    elif py2and3.isstring(rootTopic):
        from .. import pub
        rootTopic = pub.getTopic(rootTopic)

    tree = ET.Element('topicdefntree')
    if moduleDoc:
        mod_desc = ET.SubElement(tree, 'description')
        mod_desc.text = ' '.join(moduleDoc.split())

    traverser = pub.TopicTreeTraverser(XmlVisitor(tree))
    traverser.traverse(rootTopic)

    indent(tree)

    if moduleName:

        filename = '%s.xml' % moduleName
        if bak:
            pub._backupIfExists(filename, bak)

        fulltree= ET.ElementTree(tree)
        fulltree.write(filename, "utf-8", True)

    return ET.tostring(tree) 
开发者ID:xtiankisutsa,项目名称:MARA_Framework,代码行数:34,代码来源:xmltopicdefnprovider.py

示例12: serialize

# 需要导入模块: from elementtree import ElementTree [as 别名]
# 或者: from elementtree.ElementTree import ElementTree [as 别名]
def serialize(elem, encoding=None):
    import cStringIO
    file = cStringIO.StringIO()
    tree = ElementTree.ElementTree(elem)
    if encoding:
        tree.write(file, encoding)
    else:
        tree.write(file)
    return file.getvalue() 
开发者ID:seppius-xbmc-repo,项目名称:ru,代码行数:11,代码来源:selftest.py

示例13: sanity

# 需要导入模块: from elementtree import ElementTree [as 别名]
# 或者: from elementtree.ElementTree import ElementTree [as 别名]
def sanity():
    """
    >>> from elementtree.ElementTree import *
    >>> from elementtree.ElementInclude import *
    >>> from elementtree.ElementPath import *
    >>> from elementtree.HTMLTreeBuilder import *
    >>> from elementtree.SimpleXMLTreeBuilder import *
    >>> from elementtree.SimpleXMLWriter import *
    >>> from elementtree.TidyTools import *
    >>> from elementtree.XMLTreeBuilder import *
    """ 
开发者ID:seppius-xbmc-repo,项目名称:ru,代码行数:13,代码来源:selftest.py

示例14: version

# 需要导入模块: from elementtree import ElementTree [as 别名]
# 或者: from elementtree.ElementTree import ElementTree [as 别名]
def version():
    """
    >>> ElementTree.VERSION
    '1.2.7'
    """ 
开发者ID:seppius-xbmc-repo,项目名称:ru,代码行数:7,代码来源:selftest.py

示例15: interface

# 需要导入模块: from elementtree import ElementTree [as 别名]
# 或者: from elementtree.ElementTree import ElementTree [as 别名]
def interface():
    """
    Test element tree interface.

    >>> element = ElementTree.Element("tag")
    >>> check_element(element)
    >>> tree = ElementTree.ElementTree(element)
    >>> check_element_tree(tree)
    """ 
开发者ID:seppius-xbmc-repo,项目名称:ru,代码行数:11,代码来源:selftest.py


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