本文整理汇总了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)))
示例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")
# --------------------------------------------------------------------
示例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)
示例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()
示例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
示例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()
示例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 />'
"""
示例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
示例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
示例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
示例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.
示例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
示例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
示例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())
示例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()