本文整理汇总了Python中lxml.etree.ElementTree.tostring方法的典型用法代码示例。如果您正苦于以下问题:Python ElementTree.tostring方法的具体用法?Python ElementTree.tostring怎么用?Python ElementTree.tostring使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lxml.etree.ElementTree
的用法示例。
在下文中一共展示了ElementTree.tostring方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_asset
# 需要导入模块: from lxml.etree import ElementTree [as 别名]
# 或者: from lxml.etree.ElementTree import tostring [as 别名]
def create_asset(self, asset_type_name, xmldata, context_oid=""):
body = ElementTree.tostring(xmldata, encoding="utf-8")
query = {}
if context_oid:
query = {"ctx": context_oid}
path = "/rest-1.v1/Data/{0}".format(asset_type_name)
return self.get_xml(path, query=query, postdata=body)
示例2: update_cells
# 需要导入模块: from lxml.etree import ElementTree [as 别名]
# 或者: from lxml.etree.ElementTree import tostring [as 别名]
def update_cells(self, cell_list):
"""Updates cells in batch.
:param cell_list: List of a :class:`Cell` objects to update.
"""
feed = self._create_update_feed(cell_list)
self.client.post_cells(self, ElementTree.tostring(feed))
示例3: _ds
# 需要导入模块: from lxml.etree import ElementTree [as 别名]
# 或者: from lxml.etree.ElementTree import tostring [as 别名]
def _ds(elem):
"""ElementTree debug function.
Indents and renders xml tree to a string.
"""
_indent(elem)
return ElementTree.tostring(elem)
示例4: dict_to_xml
# 需要导入模块: from lxml.etree import ElementTree [as 别名]
# 或者: from lxml.etree.ElementTree import tostring [as 别名]
def dict_to_xml(obj):
"""
Return a xml representation of the given dictionary:
1. keys of the dictionary become sublements.
2. if a value is a list, then key is a set of sublements.
3. keys starting with '@' became an attribute.
{'duck': {'birth_date': '1934-06-04T00:00:00',
'created_by': {'@href': 'http://en.wikipedia.org/wiki/Walt_Disney',
'cryopreserved': True,
'name': 'Walt Disney'},
'family': {'nephew': [{'name': 'Huey'},
{'name': 'Dewey'},
{'name': 'Louie'}],
'children': [],
'uncles': {'uncle': [{'name': 'Scrooge McDuck'},
{'name': 'Ludwig Von Drake'}]}},
'first_film': None,
'last_film': None,
'name': 'Donald',
'species': {'@href': 'http://en.wikipedia.org/wiki/Pekin_duck'}}
}
<?xml version="1.0" encoding="UTF-8"?>
<duck>
<name>Donald</name>
<family>
<children />
<nephew><name>Huey</name></nephew>
<nephew><name>Dewey</name></nephew>
<nephew><name>Louie</name></nephew>
<uncles>
<uncle><name>Scrooge McDuck</name></uncle>
<uncle><name>Ludwig Von Drake</name></uncle>
</uncles>
</family>
<last_film />
<first_film />
<created_by href="http://en.wikipedia.org/wiki/Walt_Disney">
<cryopreserved>True</cryopreserved>
<name>Walt Disney</name>
</created_by>
<birth_date>1934-06-04T00:00:00</birth_date>
<species href="http://en.wikipedia.org/wiki/Pekin_duck" />
</duck>
"""
if not obj:
return
# top level dictionary must contain a single entry
# corresponding to the root element
key, value = obj.popitem()
root = etree.Element(key)
element_for_value(value, root)
return (b'<?xml version="1.0" encoding="UTF-8"?>' +
etree.tostring(root, encoding='utf-8'))
示例5: update_cell
# 需要导入模块: from lxml.etree import ElementTree [as 别名]
# 或者: from lxml.etree.ElementTree import tostring [as 别名]
def update_cell(self, row, col, val):
"""Sets the new value to a cell.
:param row: Row number.
:param col: Column number.
:param val: New value.
"""
feed = self.client.get_cells_cell_id_feed(self,
self._cell_addr(row, col))
cell_elem = feed.find(_ns1('cell'))
cell_elem.set('inputValue', unicode(val))
uri = self._get_link('edit', feed).get('href')
self.client.put_feed(uri, ElementTree.tostring(feed))
示例6: add_worksheet
# 需要导入模块: from lxml.etree import ElementTree [as 别名]
# 或者: from lxml.etree.ElementTree import tostring [as 别名]
def add_worksheet(self, title, rows, cols):
"""Adds a new worksheet to a spreadsheet.
:param title: A title of a new worksheet.
:param rows: Number of rows.
:param cols: Number of columns.
Returns a newly created :class:`worksheets <Worksheet>`.
"""
feed = Element('entry', {'xmlns': ATOM_NS,
'xmlns:gs': SPREADSHEET_NS})
SubElement(feed, 'title').text = title
SubElement(feed, 'gs:rowCount').text = str(rows)
SubElement(feed, 'gs:colCount').text = str(cols)
url = construct_url('worksheets', self)
elem = self.client.post_feed(url, ElementTree.tostring(feed))
worksheet = Worksheet(self, elem)
self._sheet_list.append(worksheet)
return worksheet
示例7: resize
# 需要导入模块: from lxml.etree import ElementTree [as 别名]
# 或者: from lxml.etree.ElementTree import tostring [as 别名]
def resize(self, rows=None, cols=None):
"""Resizes the worksheet.
:param rows: New rows number.
:param cols: New columns number.
"""
if rows is None and cols is None:
raise TypeError("Either 'rows' or 'cols' should be specified.")
self_uri = self._get_link('self', self._element).get('href')
feed = self.client.get_feed(self_uri)
uri = self._get_link('edit', feed).get('href')
if rows:
elem = feed.find(_ns1('rowCount'))
elem.text = str(rows)
if cols:
elem = feed.find(_ns1('colCount'))
elem.text = str(cols)
# Send request and store result
self._element = self.client.put_feed(uri, ElementTree.tostring(feed))
示例8: update_asset
# 需要导入模块: from lxml.etree import ElementTree [as 别名]
# 或者: from lxml.etree.ElementTree import tostring [as 别名]
def update_asset(self, asset_type_name, oid, update_doc):
newdata = ElementTree.tostring(update_doc, encoding="utf-8")
path = "/rest-1.v1/Data/{0}/{1}".format(asset_type_name, oid)
return self.get_xml(path, postdata=newdata)