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


Python ElementTree.tostring方法代码示例

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


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

示例1: to_xml_str

# 需要导入模块: from elementtree import ElementTree [as 别名]
# 或者: from elementtree.ElementTree import tostring [as 别名]
def to_xml_str(self, pretty_print=False):

        attr = {}

        if self.version:
            attr[SDX_SUNSPEC_DATA_VERSION] = self.version

        self.root = ET.Element(SDX_SUNSPEC_DATA, attrib=attr)
        for d in self.device_data:
            d.to_xml(self.root)

        if pretty_print:
            util.indent(self.root)

        out = ET.tostring(self.root)
        if sys.version_info > (3,):
            temp = ""
            for i in out:
                temp += chr(i)
            out = temp

        return out 
开发者ID:sunspec,项目名称:pysunspec,代码行数:24,代码来源:data.py

示例2: test_device_to_pics

# 需要导入模块: from elementtree import ElementTree [as 别名]
# 或者: from elementtree.ElementTree import tostring [as 别名]
def test_device_to_pics(self):
        d1 = device.Device()
        d1.from_pics(filename='pics_test_device_1.xml', pathlist=self.pathlist)

        root = ET.Element(pics.PICS_ROOT)
        d1.to_pics(root, single_repeating=False)
        # util.indent(root)
        # print(ET.tostring(root))

        d = root.find(pics.PICS_DEVICE)
        if d is None:
            raise Exception("No '{}' elements found in '{}' element".format(pics.PICS_DEVICE, root.tag))

        d2 = device.Device()
        d2.from_pics(element=d)

        not_equal = d1.not_equal(d2)
        if not_equal:
            raise Exception(not_equal) 
开发者ID:sunspec,项目名称:pysunspec,代码行数:21,代码来源:test_device.py

示例3: parseliteral

# 需要导入模块: from elementtree import ElementTree [as 别名]
# 或者: from elementtree.ElementTree import tostring [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

示例4: __SendDataPart

# 需要导入模块: from elementtree import ElementTree [as 别名]
# 或者: from elementtree.ElementTree import tostring [as 别名]
def __SendDataPart(data, connection):
  """This method is deprecated, use atom.http._send_data_part"""
  deprecated('call to deprecated function __SendDataPart')
  if isinstance(data, str):
    #TODO add handling for unicode.
    connection.send(data)
    return
  elif ElementTree.iselement(data):
    connection.send(ElementTree.tostring(data))
    return
  # Check to see if data is a file-like object that has a read method.
  elif hasattr(data, 'read'):
    # Read the file and send it a chunk at a time.
    while 1:
      binarydata = data.read(100000)
      if binarydata == '': break
      connection.send(binarydata)
    return
  else:
    # The data object was not a file.
    # Try to convert to a string and send the data.
    connection.send(str(data))
    return 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:25,代码来源:service.py

示例5: CalculateDataLength

# 需要导入模块: from elementtree import ElementTree [as 别名]
# 或者: from elementtree.ElementTree import tostring [as 别名]
def CalculateDataLength(data):
  """Attempts to determine the length of the data to send. 
  
  This method will respond with a length only if the data is a string or
  and ElementTree element.

  Args:
    data: object If this is not a string or ElementTree element this funtion
        will return None.
  """
  if isinstance(data, str):
    return len(data)
  elif isinstance(data, list):
    return None
  elif ElementTree.iselement(data):
    return len(ElementTree.tostring(data))
  elif hasattr(data, 'read'):
    # If this is a file-like object, don't try to guess the length.
    return None
  else:
    return len(str(data)) 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:23,代码来源:service.py

示例6: setup_page

# 需要导入模块: from elementtree import ElementTree [as 别名]
# 或者: from elementtree.ElementTree import tostring [as 别名]
def setup_page(self):
        self.setup_paper(self.dom_stylesheet)
        if (len(self.header_content) > 0 or len(self.footer_content) > 0 or
            self.settings.custom_header or self.settings.custom_footer):
            self.add_header_footer(self.dom_stylesheet)
        new_content = etree.tostring(self.dom_stylesheet)
        return new_content 
开发者ID:skarlekar,项目名称:faces,代码行数:9,代码来源:__init__.py

示例7: exportTopicTreeSpecXml

# 需要导入模块: from elementtree import ElementTree [as 别名]
# 或者: from elementtree.ElementTree import tostring [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

示例8: writestring

# 需要导入模块: from elementtree import ElementTree [as 别名]
# 或者: from elementtree.ElementTree import tostring [as 别名]
def writestring():
    """
    >>> elem = ElementTree.XML("<html><body>text</body></html>")
    >>> ElementTree.tostring(elem)
    '<html><body>text</body></html>'
    >>> elem = ElementTree.fromstring("<html><body>text</body></html>")
    >>> ElementTree.tostring(elem)
    '<html><body>text</body></html>'
    """ 
开发者ID:seppius-xbmc-repo,项目名称:ru,代码行数:11,代码来源:selftest.py

示例9: bug_xmltoolkit39

# 需要导入模块: from elementtree import ElementTree [as 别名]
# 或者: from elementtree.ElementTree import tostring [as 别名]
def bug_xmltoolkit39():
    """
    non-ascii element and attribute names doesn't work

    >>> tree = ElementTree.XML("<?xml version='1.0' encoding='iso-8859-1'?><t�g />")
    >>> ElementTree.tostring(tree, "utf-8")
    '<t\\xc3\\xa4g />'

    >>> tree = ElementTree.XML("<?xml version='1.0' encoding='iso-8859-1'?><tag �ttr='v&#228;lue' />")
    >>> tree.attrib
    {u'\\xe4ttr': u'v\\xe4lue'}
    >>> ElementTree.tostring(tree, "utf-8")
    '<tag \\xc3\\xa4ttr="v\\xc3\\xa4lue" />'

    >>> tree = ElementTree.XML("<?xml version='1.0' encoding='iso-8859-1'?><t�g>text</t�g>")
    >>> ElementTree.tostring(tree, "utf-8")
    '<t\\xc3\\xa4g>text</t\\xc3\\xa4g>'

    >>> tree = ElementTree.Element(u"t�g")
    >>> ElementTree.tostring(tree, "utf-8")
    '<t\\xc3\\xa4g />'

    >>> tree = ElementTree.Element("tag")
    >>> tree.set(u"�ttr", u"v�lue")
    >>> ElementTree.tostring(tree, "utf-8")
    '<tag \\xc3\\xa4ttr="v\\xc3\\xa4lue" />'

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

示例10: test_et

# 需要导入模块: from elementtree import ElementTree [as 别名]
# 或者: from elementtree.ElementTree import tostring [as 别名]
def test_et():
        """ElementTree"""
        _table = et.Element('table')
        for row in table:
            tr = et.SubElement(_table, 'tr')
            for c in row.values():
                et.SubElement(tr, 'td').text=str(c)
        et.tostring(_table) 
开发者ID:youtube,项目名称:spitfire,代码行数:10,代码来源:bigtable.py

示例11: test_cet

# 需要导入模块: from elementtree import ElementTree [as 别名]
# 或者: from elementtree.ElementTree import tostring [as 别名]
def test_cet():
        """cElementTree"""
        _table = cet.Element('table')
        for row in table:
            tr = cet.SubElement(_table, 'tr')
            for c in row.values():
                cet.SubElement(tr, 'td').text=str(c)
        cet.tostring(_table) 
开发者ID:youtube,项目名称:spitfire,代码行数:10,代码来源:bigtable.py

示例12: ToString

# 需要导入模块: from elementtree import ElementTree [as 别名]
# 或者: from elementtree.ElementTree import tostring [as 别名]
def ToString(self, string_encoding='UTF-8'):
    """Converts the Atom object to a string containing XML."""
    return ElementTree.tostring(self._ToElementTree(), encoding=string_encoding) 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:5,代码来源:__init__.py

示例13: to_string

# 需要导入模块: from elementtree import ElementTree [as 别名]
# 或者: from elementtree.ElementTree import tostring [as 别名]
def to_string(self, version=1, encoding=None, pretty_print=None):
    """Converts this object to XML."""

    tree_string = ElementTree.tostring(self._to_tree(version, encoding))

    if pretty_print and xmlString is not None:
        return xmlString(tree_string).toprettyxml()
 
    if isinstance(tree_string, str):
      return tree_string
    else:
      # For Python 3
      return tree_string.decode() 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:15,代码来源:core.py

示例14: ToString

# 需要导入模块: from elementtree import ElementTree [as 别名]
# 或者: from elementtree.ElementTree import tostring [as 别名]
def ToString(self):
    element_tree = self._TransferToElementTree(ElementTree.Element(''))
    return ElementTree.tostring(element_tree, encoding="UTF-8") 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:5,代码来源:__init__.py

示例15: to_string

# 需要导入模块: from elementtree import ElementTree [as 别名]
# 或者: from elementtree.ElementTree import tostring [as 别名]
def to_string(self, version=1, encoding=None):
    """Converts this object to XML."""
    return ElementTree.tostring(self._to_tree(version, encoding)) 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:5,代码来源:core.py


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