Exemple #1
0
def writexml_element(self, writer, indent="", addindent="", newl=""):
    writer.write(newl + indent+"<" + self.tagName)

    attrs = self._get_attributes()
    a_names = attrs.keys()
    a_names.sort()

    onetextnode = False
    for a_name in a_names:
        writer.write(" %s=\"" % a_name)
        _write_data(writer, attrs[a_name].value)
        writer.write("\"")
    if self.childNodes:
        writer.write(">")
        lastnodetype=self.childNodes[0].nodeType
        for node in self.childNodes:
            if lastnodetype==node.TEXT_NODE:
                node.writexml(writer,"","","")
            else:
                node.writexml(writer, ("%s%s") % (indent,addindent), addindent, newl)
            lastnodetype=node.nodeType
        if lastnodetype==node.TEXT_NODE:
            writer.write("</%s>" % (self.tagName))
        else:
            writer.write("%s%s</%s>" % (newl,indent,self.tagName))
    else:
        writer.write("/>")
Exemple #2
0
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))
Exemple #3
0
def 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 = sorted(attrs.keys())

    for a_name in a_names:
        writer.write(" %s=\"" % 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("</%s>%s" % (self.tagName, newl))
    else:
        # Change against master: qutebrowser doesn't handle short tags
        # well. Font type escapes out, this is problem with <pre><code/></pre>
        writer.write("></%s>%s" % (self.tagName, newl))
Exemple #4
0
        def 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 = list(attrs.keys())
            a_names.sort()

            for a_name in a_names:
                writer.write(" %s=\"" % a_name)
                _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("</%s>%s" % (self.tagName, newl))
            else:
                writer.write("/>%s" % (newl))
Exemple #5
0
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(' {0}="'.format(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('</{0}>{1}'.format(self.tagName, newl))
            return
        writer.write('>{0}'.format(newl))
        for node in self.childNodes:
            node.writexml(writer,indent+addindent,addindent,newl)
        writer.write('{0}</{1}>{2}'.format(indent,self.tagName,newl))
    else:
        writer.write('/>{0}'.format(newl))
def fixed_writexml(self, writer, indent='', addindent='', newl=''):
    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)
Exemple #7
0
def writexml_element(self, writer, indent="", addindent="", newl=""):
    writer.write(newl + indent + "<" + self.tagName)

    attrs = self._get_attributes()
    a_names = attrs.keys()
    a_names.sort()

    onetextnode = False
    for a_name in a_names:
        writer.write(" %s=\"" % a_name)
        _write_data(writer, attrs[a_name].value)
        writer.write("\"")
    if self.childNodes:
        writer.write(">")
        lastnodetype = self.childNodes[0].nodeType
        for node in self.childNodes:
            if lastnodetype == node.TEXT_NODE:
                node.writexml(writer, "", "", "")
            else:
                node.writexml(writer, ("%s%s") % (indent, addindent),
                              addindent, newl)
            lastnodetype = node.nodeType
        if lastnodetype == node.TEXT_NODE:
            writer.write("</%s>" % (self.tagName))
        else:
            writer.write("%s%s</%s>" % (newl, indent, self.tagName))
    else:
        writer.write("/>")
Exemple #8
0
def writexml_ex(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)
        dom._write_data(writer, attrs[a_name].value)
        writer.write("\"")
    if self.childNodes:
        if len(self.childNodes) == 1 \
          and self.childNodes[0].nodeType == dom.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 dom.Node.TEXT_NODE:
                node.writexml(writer,indent+addindent,addindent,newl)
        writer.write("%s</%s>%s" % (indent,self.tagName,newl))
    else:
        writer.write("/>%s"%(newl))
Exemple #9
0
def fixed_writexml(self, writer, indent='', addindent='', newl=''):
    writer.write(indent + '<' + self.tagName)
    attrs = self._get_attributes()
    a_names = list(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)
Exemple #10
0
def fixed_writexml(self, writer, indent="", addindent="", newl=""):
    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))
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))
Exemple #12
0
 def writexml(self, writer, indent="", addindent="", newl=""):
     """ Write XML to the writer object """
     # indent = current indentation
     # addindent = indetation 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)
         xdm._write_data(writer, attrs[a_name].value)
         writer.write("\"")
     
     if self.childNodes:
         newl2 = newl
         if len(self.childNodes) == 1 and self.childNodes[0].nodeType == xdm.Node.TEXT_NODE:
             indent, addindent, newl = "", "", ""            
         writer.write(">%s" %(newl))
         
         for node in self.childNodes:
             node.writexml(writer, indent+addindent, addindent, newl)                            
         writer.write("%s</%s>%s" %(indent, self.tagName, newl2))            
     else:
         writer.write("/>%s" %(newl))
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 = list(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))
Exemple #14
0
        def 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)
                _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("</%s>%s" % (self.tagName, newl))
            else:
                writer.write("/>%s"%(newl))
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:
            node.writexml(writer, indent + addindent, addindent, newl)
        writer.write("%s</%s>%s" % (indent, self.tagName, newl))
    else:
        writer.write("/>%s" % (newl))
Exemple #16
0
def fixed_writexml(self, writer, indent="", addindent="", newl=""):
    """
     S.fixed_writexml(self, writer, indent, addindent)
     由于minidom默认的writexml()函数在读取一个xml文件后,修改后重新写入如果加了newl='\n',会将原有的xml中写入多余的行
     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))
Exemple #17
0
 def writexml( self, writer, indent="", addindent="", newl="" ):
     """
         \remarks    overloads the base xml.dom.minidom.Document
                     writexml method to make the pretty xml generation
                     a little prettier - doesn't create endlines after
                     every text node.
         
         \param      writer      <file> || <stream>
         \param      indent      <str>               current indent level
         \param      addindent   <str>               indentation to addindent
         \param      newl        <str>               new line character
         
         \return     <str>
     """
     _write_data(writer, '%s' % self.data)
Exemple #18
0
def writexml_helper(self, writer, indent="", addindent="", newl=""):
    """A replacement for writexml that formats it like typical XML files.
    Nodes are intendented but text nodes, where whitespace can be
    significant, are not indented."""
    # 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:
        # We need to write text nodes without newline and indentation, so
        # we handle them differently. Note that we here assume that "empty"
        # text nodes can be done away with (see the strip()). Note also that
        # nested tags in a text node (like ph tags in xliff) should also not
        # have newlines and indentation or an extra newline, since that will
        # alter the text node.
        haveText = False
        for childNode in self.childNodes:
            if childNode.nodeType == self.TEXT_NODE and childNode.data.strip():
                haveText = True
                break
        if haveText:
            writer.write(">")
            for node in self.childNodes:
                node.writexml(writer, "", "", "")
            writer.write("</%s>%s" % (self.tagName, newl))
        else:
            # This is the normal case that we do with pretty layout
            writer.write(">%s" % (newl))
            for node in self.childNodes:
                if node.nodeType != self.TEXT_NODE:
                    node.writexml(writer, (indent + addindent), addindent,
                                  newl)
            writer.write("%s</%s>%s" % (indent, self.tagName, newl))
    else:
        writer.write("/>%s" % (newl))
Exemple #19
0
 def writexml(self, writer, indent="", addindent="", newl=""):
     """
         \remarks    overloads the base xml.dom.minidom.Element
                     writexml method to make the pretty xml generation
                     a little prettier - doesn't create endlines after
                     every text node.
         
         \param      writer      <file> || <stream>
         \param      indent      <str>               current indent level
         \param      addindent   <str>               indentation to addindent
         \param      newl        <str>               new line character
         
         \return     <str>
     """
     writer.write('%s%s<%s' % (newl,indent,self.tagName))
     
     # collect and record the attributes by name
     attrs = self._get_attributes()
     a_names = attrs.keys()
     a_names.sort()
     
     # record the attributes
     for a_name in a_names:
         writer.write(' %s="' % a_name)
         _write_data(writer, attrs[a_name].value)
         writer.write('"')
         
     # record the children
     if self.childNodes:
         writer.write('>')
         for node in self.childNodes:
             if ( node.nodeType == Element.TEXT_NODE ):
                 node.writexml( writer, '', '', '' )
             else:
                 node.writexml( writer, indent + addindent, addindent, newl )
             
             lastnodetype = node.nodeType
             
         if ( lastnodetype == Element.TEXT_NODE ):
             writer.write('</%s>' % self.tagName)
         else:
             writer.write( '%s%s</%s>' % (newl,indent,self.tagName) )
     else:
         writer.write('/>')
Exemple #20
0
def writexml_helper(self, writer, indent="", addindent="", newl=""):
    """A replacement for writexml that formats it like typical XML files.
    Nodes are intendented but text nodes, where whitespace can be significant,
    are not indented.
    """
    # indent = current indentation
    # addindent = indentation to add to higher levels
    # newl = newline string
    writer.write(indent + "<" + self.tagName)

    attrs = self._get_attributes()
    a_names = sorted(attrs.keys())

    for a_name in a_names:
        writer.write(" %s=\"" % a_name)
        minidom._write_data(writer, attrs[a_name].value)
        writer.write("\"")
    if self.childNodes:
        # We need to write text nodes without newline and indentation, so
        # we handle them differently. Note that we here assume that "empty"
        # text nodes can be done away with (see the strip()). Note also that
        # nested tags in a text node (like ph tags in xliff) should also not
        # have newlines and indentation or an extra newline, since that will
        # alter the text node.
        haveText = False
        for childNode in self.childNodes:
            if childNode.nodeType == self.TEXT_NODE and childNode.data.strip():
                haveText = True
                break
        if haveText:
            writer.write(">")
            for node in self.childNodes:
                node.writexml(writer, "", "", "")
            writer.write("</%s>%s" % (self.tagName, newl))
        else:
            # This is the normal case that we do with pretty layout
            writer.write(">%s" % (newl))
            for node in self.childNodes:
                if node.nodeType != self.TEXT_NODE:
                    node.writexml(writer, (indent + addindent), addindent, newl)
            writer.write("%s</%s>%s" % (indent, self.tagName, newl))
    else:
        writer.write("/>%s" % (newl))
Exemple #21
0
def fixed_writexml(self, indent="", addindent="", newl="", writer=None):
    """fixed_writexml

    :param self:XML node
    :param indent:current indentation
    :param addindent:indentation to add to higher levels
    :param newl:newline string
    """
    # the root of recursion tree
    proot = False
    # it's all hack, waste of resources etc, but does pretty good result
    if not writer:
        from StringIO import StringIO
        writer = StringIO()
        proot = True

    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:
            fixed_writexml(node, indent + addindent, addindent, newl, writer)
        writer.write("%s</%s>%s" % (indent, self.tagName, newl))
    else:
        writer.write("/>%s" % (newl))

    return parseString(writer.getvalue()) if proot else None
Exemple #22
0
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:
        if len(a_names) > 1:
            writer.write(newl)
            writer.write(indent)
            data_indent = "    "
        else:
            data_indent = " "
        writer.write("%s%s=\"" % (data_indent, a_name))
        _write_data(writer, attrs[a_name].value)
        writer.write("\"")
    if self.childNodes:
        if len(self.childNodes) == 1 and self.childNodes[0].nodeType == Node.TEXT_NODE:
            writer.write(">")
            if len(a_names) > 1:
                writer.write(newl)
                writer.write(indent+addindent)
            self.childNodes[0].writexml(writer, "", "", "")
            if len(a_names) > 1:
                data_newl = newl
                data_indent = indent
            else:
                data_newl = ''
                data_indent = ''
            writer.write("%s%s</%s>%s" % (data_newl, data_indent, self.tagName, newl))
            return
        writer.write(">%s"%(newl))
        for node in self.childNodes:
            node.writexml(writer,indent+addindent,addindent,newl)
        writer.write("%s</%s>%s" % (indent,self.tagName,newl))
    else:
        writer.write("/>%s"%(newl))
Exemple #23
0
 def writexml(self, writer, indent="", addindent="", newl=""):
     # http://ronrothman.com/public/leftbraned/xml-dom-minidom-toprettyxml-and-silly-whitespace/
     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)
         _write_data(writer, attrs[a_name].value)
         writer.write('"')
     if self.childNodes:
         if len(self.childNodes) == 1 and self.childNodes[0].nodeType == 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:
             node.writexml(writer, indent + addindent, addindent, newl)
         writer.write("%s</%s>%s" % (indent, self.tagName, newl))
     else:
         writer.write("/>%s" % (newl))
def writexml(self, writer, indent="", addindent="", newl=""):
    #credit: http://ronrothman.com/public/leftbraned/xml-dom-minidom-toprettyxml-and-silly-whitespace/
    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)
        _write_data(writer, attrs[a_name].value)
        writer.write("\"")
    if self.childNodes:
        if len(self.childNodes) == 1 \
          and self.childNodes[0].nodeType == 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:
            node.writexml(writer, indent + addindent, addindent, newl)
        writer.write("%s</%s>%s" % (indent, self.tagName, newl))
    else:
        writer.write("/>%s" % (newl))
Exemple #25
0
def fixed_writexml(self, writer, indent="", addindent="", newl=""):
    writer.write(indent + "<" + self.tagName)
    attrs = self._get_attributes()
    a_names = attrs.keys()
    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))
Exemple #26
0
def fixed_writexml(self, writer, indent='', addindent='', newl=''):
    writer.write(f'{indent}<{self.tagName}')
    attrs = self._get_attributes()
    a_names = list(attrs.keys())
    a_names.sort()
    for a_name in a_names:
        writer.write(f' {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(f'</{self.tagName}>{newl}')
            return
        writer.write(f'>{newl}')
        for node in self.childNodes:
            if node.nodeType is not minidom.Node.TEXT_NODE:
                node.writexml(writer, indent + addindent, addindent, newl)
        writer.write(f'{indent}</{self.tagName}>{newl}')
    else:
        writer.write(f'/>{newl}')
Exemple #27
0
    def writexml(self, writer, indent="", addindent="", newl=""):
        writer.write(indent + "<" + self.tagName)

        attrs = self._get_attributes()
        # a_names = sorted(attrs.keys())
        a_names = attrs.keys()

        for a_name in a_names:
            writer.write(" %s=\"" % a_name)
            _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("</%s>%s" % (self.tagName, newl))
        else:
            writer.write("/>%s" % (newl))
Exemple #28
0
 def writexml(self, writer, indent="", addindent="", newl=""):
     _write_data(writer, "%s%s%s" % (indent, self.data, newl))
Exemple #29
0
 def writexml_text(self, writer, indent='', addindent='', newl=''):
     text = self.data.strip()
     if text:
         minidom._write_data(writer, "%s%s%s" % (indent, text, newl))
def _writexml_text(self, writer, indent="", addindent="", newl=""):
        minidom._write_data(writer, "%s"%(self.data.strip()))
 def writexml_text(self, writer, indent='', addindent='', newl=''):
     text = self.data.strip()
     if text:
         minidom._write_data(writer, "%s%s%s" % (indent, text, newl))
Exemple #32
0
def writexml_text(self, writer, indent="", addindent="", newl=""):
    _write_data(writer, "%s%s%s" % ('', self.data.strip(), newl))