當前位置: 首頁>>代碼示例>>Python>>正文


Python ElementTree.TreeBuilder方法代碼示例

本文整理匯總了Python中xml.etree.ElementTree.TreeBuilder方法的典型用法代碼示例。如果您正苦於以下問題:Python ElementTree.TreeBuilder方法的具體用法?Python ElementTree.TreeBuilder怎麽用?Python ElementTree.TreeBuilder使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在xml.etree.ElementTree的用法示例。


在下文中一共展示了ElementTree.TreeBuilder方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: parse

# 需要導入模塊: from xml.etree import ElementTree [as 別名]
# 或者: from xml.etree.ElementTree import TreeBuilder [as 別名]
def parse(source, binaryfp=None):
    """Parse ArtsXML file from source.

    Args:
        source (str): Filename or file pointer.

    Returns:
        xml.etree.ElementTree: XML Tree of the ARTS data file.

    """
    arts_element = type('ARTSElementBinaryFP',
                        ARTSElement.__bases__,
                        dict(ARTSElement.__dict__))
    arts_element.binaryfp = binaryfp
    return ElementTree.parse(source,
                             parser=ElementTree.XMLParser(
                                 target=ElementTree.TreeBuilder(
                                     element_factory=arts_element))) 
開發者ID:atmtools,項目名稱:typhon,代碼行數:20,代碼來源:read.py

示例2: xmltoolkit63

# 需要導入模塊: from xml.etree import ElementTree [as 別名]
# 或者: from xml.etree.ElementTree import TreeBuilder [as 別名]
def xmltoolkit63():
    """

    Check reference leak.
    >>> xmltoolkit63()
    >>> count = sys.getrefcount(None)
    >>> for i in range(1000):
    ...     xmltoolkit63()
    >>> sys.getrefcount(None) - count
    0

    """
    tree = ET.TreeBuilder()
    tree.start("tag", {})
    tree.data("text")
    tree.end("tag")

# -------------------------------------------------------------------- 
開發者ID:dxwu,項目名稱:BinderFilter,代碼行數:20,代碼來源:test_xml_etree.py

示例3: __init__

# 需要導入模塊: from xml.etree import ElementTree [as 別名]
# 或者: from xml.etree.ElementTree import TreeBuilder [as 別名]
def __init__(self, quiet=False):
        if sys.flags.optimize >= 2:
            # under -OO, doctests cannot be run and therefore not all warnings
            # will be emitted
            quiet = True
        deprecations = (
            # Search behaviour is broken if search path starts with "/".
            ("This search is broken in 1.3 and earlier, and will be fixed "
             "in a future version.  If you rely on the current behaviour, "
             "change it to '.+'", FutureWarning),
            # Element.getchildren() and Element.getiterator() are deprecated.
            ("This method will be removed in future versions.  "
             "Use .+ instead.", DeprecationWarning),
            ("This method will be removed in future versions.  "
             "Use .+ instead.", PendingDeprecationWarning),
            # XMLParser.doctype() is deprecated.
            ("This method of XMLParser is deprecated.  Define doctype.. "
             "method on the TreeBuilder target.", DeprecationWarning))
        self.checkwarnings = test_support.check_warnings(*deprecations,
                                                         quiet=quiet) 
開發者ID:dxwu,項目名稱:BinderFilter,代碼行數:22,代碼來源:test_xml_etree.py

示例4: add_gdal_warp_options_to_string

# 需要導入模塊: from xml.etree import ElementTree [as 別名]
# 或者: from xml.etree.ElementTree import TreeBuilder [as 別名]
def add_gdal_warp_options_to_string(vrt_string, warp_options):
    if not warp_options:
        return vrt_string

    vrt_root = ElementTree.fromstring(vrt_string)
    options = vrt_root.find("GDALWarpOptions")

    if options is None:
        return vrt_string

    for key, value in warp_options.items():
        tb = ElementTree.TreeBuilder()
        tb.start("Option", {"name": key})
        tb.data(value)
        tb.end("Option")
        elem = tb.close()
        options.insert(0, elem)

    return ElementTree.tostring(vrt_root).decode() 
開發者ID:Luqqk,項目名稱:gdal2tiles,代碼行數:21,代碼來源:gdal2tiles.py

示例5: __init__

# 需要導入模塊: from xml.etree import ElementTree [as 別名]
# 或者: from xml.etree.ElementTree import TreeBuilder [as 別名]
def __init__(self, target=None, validating=False):
        if not compas.is_ironpython():
            raise Exception('CLRXMLTreeParser can only be used from IronPython')

        settings = XmlReaderSettings()
        settings.IgnoreComments = True
        settings.IgnoreProcessingInstructions = True
        settings.IgnoreWhitespace = True
        if not validating:
            settings.DtdProcessing = DtdProcessing.Ignore
            settings.ValidationType = getattr(ValidationType, 'None')
        else:
            settings.DtdProcessing = DtdProcessing.Parse
            settings.ValidationType = ValidationType.DTD
        self.settings = settings
        self._target = (target if (target is not None) else ET.TreeBuilder())
        self._buffer = []
        self._document_encoding = 'UTF-8'  # default 
開發者ID:compas-dev,項目名稱:compas,代碼行數:20,代碼來源:xml_cli.py

示例6: parse

# 需要導入模塊: from xml.etree import ElementTree [as 別名]
# 或者: from xml.etree.ElementTree import TreeBuilder [as 別名]
def parse(self, encoding=None, errors='strict', **kwargs):
        """
        Return the contents of toolbox settings file with a nested structure.

        :param encoding: encoding used by settings file
        :type encoding: str
        :param errors: Error handling scheme for codec. Same as ``decode()`` builtin method.
        :type errors: str
        :param kwargs: Keyword arguments passed to ``StandardFormat.fields()``
        :type kwargs: dict
        :rtype: ElementTree._ElementInterface
        """
        builder = 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 builder.close() 
開發者ID:rafasashi,項目名稱:razzy-spinner,代碼行數:34,代碼來源:toolbox.py

示例7: bug_1534630

# 需要導入模塊: from xml.etree import ElementTree [as 別名]
# 或者: from xml.etree.ElementTree import TreeBuilder [as 別名]
def bug_1534630():
    """

    >>> bob = ET.TreeBuilder()
    >>> e = bob.data("data")
    >>> e = bob.start("tag", {})
    >>> e = bob.end("tag")
    >>> e = bob.close()
    >>> serialize(e)
    '<tag />'

    """ 
開發者ID:dxwu,項目名稱:BinderFilter,代碼行數:14,代碼來源:test_xml_etree.py

示例8: __init__

# 需要導入模塊: from xml.etree import ElementTree [as 別名]
# 或者: from xml.etree.ElementTree import TreeBuilder [as 別名]
def __init__(self):
        et.TreeBuilder.__init__(self)
        self.root_element = None
        self.root_element_closed = False 
開發者ID:IBM,項目名稱:pyxcli,代碼行數:6,代碼來源:xml_util.py

示例9: start

# 需要導入模塊: from xml.etree import ElementTree [as 別名]
# 或者: from xml.etree.ElementTree import TreeBuilder [as 別名]
def start(self, tag, attrs):
        element = et.TreeBuilder.start(self, tag, attrs)
        if self.root_element is None:
            self.root_element = element
        return element 
開發者ID:IBM,項目名稱:pyxcli,代碼行數:7,代碼來源:xml_util.py

示例10: end

# 需要導入模塊: from xml.etree import ElementTree [as 別名]
# 或者: from xml.etree.ElementTree import TreeBuilder [as 別名]
def end(self, tag):
        element = et.TreeBuilder.end(self, tag)
        if self.root_element is element:
            self.root_element_closed = True
        return element 
開發者ID:IBM,項目名稱:pyxcli,代碼行數:7,代碼來源:xml_util.py

示例11: __init__

# 需要導入模塊: from xml.etree import ElementTree [as 別名]
# 或者: from xml.etree.ElementTree import TreeBuilder [as 別名]
def __init__(self, encoding=None):
        self.__stack = []
        self.__builder = ET.TreeBuilder()
        self.encoding = encoding or "iso-8859-1"
        HTMLParser.__init__(self)

    ##
    # Flushes parser buffers, and return the root element.
    #
    # @return An Element instance. 
開發者ID:alexfeng,項目名稱:InternationalizationScript-iOS,代碼行數:12,代碼來源:pythondoc.py

示例12: message

# 需要導入模塊: from xml.etree import ElementTree [as 別名]
# 或者: from xml.etree.ElementTree import TreeBuilder [as 別名]
def message(self):
        builder = TreeBuilder()
        builder.start(self.resource_type, dict())
        self.serialize(builder)
        builder.end(self.resource_type)
        msg = tostring(builder.close())
        return msg 
開發者ID:planetfederal,項目名稱:qgis-geoserver-plugin,代碼行數:9,代碼來源:support.py

示例13: __init__

# 需要導入模塊: from xml.etree import ElementTree [as 別名]
# 或者: from xml.etree.ElementTree import TreeBuilder [as 別名]
def __init__(self):
    HTMLParser.HTMLParser.__init__(self)
    self.tree_builder = ElementTree.TreeBuilder()
    self.tree = None 
開發者ID:khalim19,項目名稱:gimp-plugin-export-layers,代碼行數:6,代碼來源:process_local_docs.py

示例14: generate

# 需要導入模塊: from xml.etree import ElementTree [as 別名]
# 或者: from xml.etree.ElementTree import TreeBuilder [as 別名]
def generate(self, feeds: List[Feed]) -> None:
        """Create subscriptions document from list of feeds.

        Args:
            feeds: the list of feeds to include in the document
        """
        builder = ElementTree.TreeBuilder()

        builder.start("opml", {'version': '2.0'})
        builder.start("head", {})
        builder.start("title", {})
        builder.data("castero feeds")
        builder.end("title")
        builder.end("head")
        builder.start("body", {})
        for feed in feeds:
            builder.start("outline", {
                'type': 'rss',
                'text': str(feed),
                'xmlUrl': feed.key
            })
            builder.end("outline")
        builder.end("body")
        builder.end("opml")

        # .close returns an Element, so we need to cast to an ElementTree
        self._tree = ElementTree.ElementTree(builder.close()) 
開發者ID:xgi,項目名稱:castero,代碼行數:29,代碼來源:subscriptions.py

示例15: parse

# 需要導入模塊: from xml.etree import ElementTree [as 別名]
# 或者: from xml.etree.ElementTree import TreeBuilder [as 別名]
def parse(self, encoding=None, errors='strict', **kwargs):
        """
        Return the contents of toolbox settings file with a nested structure.

        :param encoding: encoding used by settings file
        :type encoding: str
        :param errors: Error handling scheme for codec. Same as ``decode()`` builtin method.
        :type errors: str
        :param kwargs: Keyword arguments passed to ``StandardFormat.fields()``
        :type kwargs: dict
        :rtype: ElementTree._ElementInterface
        """
        builder = 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 builder.close() 
開發者ID:V1EngineeringInc,項目名稱:V1EngineeringInc-Docs,代碼行數:34,代碼來源:toolbox.py


注:本文中的xml.etree.ElementTree.TreeBuilder方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。