本文整理汇总了Python中xml.dom.minidom._write_data方法的典型用法代码示例。如果您正苦于以下问题:Python minidom._write_data方法的具体用法?Python minidom._write_data怎么用?Python minidom._write_data使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xml.dom.minidom
的用法示例。
在下文中一共展示了minidom._write_data方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _writexml_text
# 需要导入模块: from xml.dom import minidom [as 别名]
# 或者: from xml.dom.minidom import _write_data [as 别名]
def _writexml_text(self, writer, indent="", addindent="", newl=""):
minidom._write_data(writer, "%s"%(self.data.strip()))
示例2: _writexml_element
# 需要导入模块: from xml.dom import minidom [as 别名]
# 或者: from xml.dom.minidom import _write_data [as 别名]
def _writexml_element(self, writer, indent="", addindent="", newl=""):
# indent = current indentation
# addindent = indentation to add to higher levels
# newl = newline string
writer.write(indent+"<" + self.tagName)
attrs = self._get_attributes()
a_names = attrs.keys()
a_names.sort()
for a_name in a_names:
writer.write(" %s=\"" % a_name)
minidom._write_data(writer, attrs[a_name].value)
writer.write("\"")
if self.childNodes:
if self.childNodes[0].nodeType == Node.TEXT_NODE and len(self.childNodes[0].data) > 0:
writer.write(">")
else:
writer.write(">%s"%(newl))
for node in self.childNodes:
node.writexml(writer,indent+addindent,addindent,newl)
if self.childNodes[-1].nodeType == Node.TEXT_NODE and len(self.childNodes[0].data) > 0:
writer.write("</%s>%s" % (self.tagName,newl))
else:
writer.write("%s</%s>%s" % (indent,self.tagName,newl))
else:
writer.write("/>%s"%(newl))
示例3: fixed_writexml
# 需要导入模块: from xml.dom import minidom [as 别名]
# 或者: from xml.dom.minidom import _write_data [as 别名]
def fixed_writexml(self, writer, indent="", addindent="", newl=""):
# indent = current indentation
# addindent = indentation to add to higher levels
# newl = newline string
writer.write(indent+"<" + self.tagName)
attrs = self._get_attributes()
a_names = attrs.keys()
a_names.sort()
for a_name in a_names:
writer.write(" %s=\"" % a_name)
minidom._write_data(writer, attrs[a_name].value)
writer.write("\"")
if self.childNodes:
if len(self.childNodes) == 1 \
and self.childNodes[0].nodeType == minidom.Node.TEXT_NODE:
writer.write(">")
self.childNodes[0].writexml(writer, "", "", "")
writer.write("</%s>%s" % (self.tagName, newl))
return
writer.write(">%s"%(newl))
for node in self.childNodes:
if node.nodeType is not minidom.Node.TEXT_NODE:
node.writexml(writer,indent+addindent,addindent,newl)
writer.write("%s</%s>%s" % (indent,self.tagName,newl))
else:
writer.write("/>%s"%(newl))
# replace minidom's function with ours
示例4: monkeypatch_element_xml
# 需要导入模块: from xml.dom import minidom [as 别名]
# 或者: from xml.dom.minidom import _write_data [as 别名]
def monkeypatch_element_xml(self, writer, indent="", addindent="", newl=""):
"""Format scenario step elements.
Ensures a stable and predictable order to the attributes of these
elements with the most important information always coming first,
then let all other elements follow in alphabetical order.
"""
writer.write("{}<{}".format(indent, self.tagName))
attrs = self._get_attributes()
a_names = sorted(attrs.keys(), key=AttributeSorter)
for a_name in a_names:
writer.write(" {}=\"".format(a_name))
minidom._write_data(writer, attrs[a_name].value)
writer.write("\"")
if self.childNodes:
writer.write(">")
if (len(self.childNodes) == 1 and
self.childNodes[0].nodeType == Node.TEXT_NODE):
self.childNodes[0].writexml(writer, '', '', '')
else:
writer.write(newl)
for node in self.childNodes:
node.writexml(writer, indent+addindent, addindent, newl)
writer.write(indent)
writer.write("</{}>{}".format(self.tagName, newl))
else:
writer.write("/>{}".format(newl))