當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。