added reusage of xml output and removed toprettyxml which has lots and lots of problems (output once stored is not usable any more from any xml parser/reader because it adds whitespaces all over the output just to be more 'human' readable)

This commit is contained in:
Miroslav Stampar 2010-06-03 07:36:30 +00:00
parent 080c71b903
commit 464f171a8c

View File

@ -1,10 +1,14 @@
#!/usr/bin/env python #!/usr/bin/env python
import codecs import codecs
import os
import re import re
import xml
import xml.sax.saxutils as saxutils import xml.sax.saxutils as saxutils
from xml.dom.minidom import Document from xml.dom.minidom import Document
from xml.parsers.expat import ExpatError
from lib.core.common import getUnicode from lib.core.common import getUnicode
from lib.core.data import conf from lib.core.data import conf
@ -478,11 +482,22 @@ class XMLDump:
if (conf.xmlFile) : if (conf.xmlFile) :
try : try :
self.__outputFile = conf.xmlFile self.__outputFile = conf.xmlFile
self.__outputFP = codecs.open(self.__outputFile, "a", conf.dataEncoding) self.__root = None
self.__root = self.__doc.createElementNS(NAME_SPACE_ATTR, RESULTS_ELEM_NAME)
self.__root.setAttributeNode(self.__createAttribute(XMLNS_ATTR,NAME_SPACE_ATTR)) if os.path.exists(self.__outputFile):
self.__root.setAttributeNode(self.__createAttribute(SCHEME_NAME_ATTR,SCHEME_NAME)) try:
self.__doc.appendChild(self.__root) self.__doc = xml.dom.minidom.parse(self.__outputFile)
self.__root = self.__doc.childNodes[0]
except ExpatError:
pass
self.__outputFP = codecs.open(self.__outputFile, "w+", conf.dataEncoding)
if self.__root is None:
self.__root = self.__doc.createElementNS(NAME_SPACE_ATTR, RESULTS_ELEM_NAME)
self.__root.setAttributeNode(self.__createAttribute(XMLNS_ATTR,NAME_SPACE_ATTR))
self.__root.setAttributeNode(self.__createAttribute(SCHEME_NAME_ATTR,SCHEME_NAME))
self.__doc.appendChild(self.__root)
except IOError, e: except IOError, e:
raise sqlmapFilePathException("Wrong filename provided for saving the xml file: %s" % conf.xmlFile) raise sqlmapFilePathException("Wrong filename provided for saving the xml file: %s" % conf.xmlFile)
@ -509,7 +524,8 @@ class XMLDump:
statusElem.appendChild(errorElem) statusElem.appendChild(errorElem)
self.__addToRoot(statusElem) self.__addToRoot(statusElem)
self.__write(self.__doc.toprettyxml(encoding=conf.dataEncoding)) #self.__write(self.__doc.toprettyxml(encoding=conf.dataEncoding)) ##don't use toprettyxml, lots of bugs with it
self.__write(self.__doc.toxml(encoding=conf.dataEncoding)) ##not human readable, but at least without bugs
self.__outputFP.close() self.__outputFP.close()
def closeDumper(status, msg=""): def closeDumper(status, msg=""):