我们从Python开源项目中,提取了以下11个代码示例,用于说明如何使用xml.dom.minidom._write_data()。
def _writexml_text(self, writer, indent="", addindent="", newl=""): minidom._write_data(writer, "%s"%(self.data.strip()))
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))
def patch_minidom(): """ Because default version outputs to much whitespace """ def writexml_text(self, writer, indent='', addindent='', newl=''): text = self.data.strip() if text: minidom._write_data(writer, "%s%s%s" % (indent, text, newl)) minidom.Text.writexml = writexml_text
def patch_minidom(): ''' Because default version outputs to much whitespace ''' def writexml_text(self, writer, indent='', addindent='', newl=''): text = self.data.strip() if text: minidom._write_data(writer, "%s%s%s" % (indent, text, newl)) minidom.Text.writexml = writexml_text