Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 464f171

Browse files
committed
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)
1 parent 080c71b commit 464f171

1 file changed

Lines changed: 23 additions & 7 deletions

File tree

lib/core/xmldump.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
#!/usr/bin/env python
22

33
import codecs
4+
import os
45
import re
6+
import xml
57

68
import xml.sax.saxutils as saxutils
9+
710
from xml.dom.minidom import Document
11+
from xml.parsers.expat import ExpatError
812

913
from lib.core.common import getUnicode
1014
from lib.core.data import conf
@@ -477,12 +481,23 @@ def setOutputFile(self):
477481
'''
478482
if (conf.xmlFile) :
479483
try :
480-
self.__outputFile = conf.xmlFile
481-
self.__outputFP = codecs.open(self.__outputFile, "a", conf.dataEncoding)
482-
self.__root = self.__doc.createElementNS(NAME_SPACE_ATTR, RESULTS_ELEM_NAME)
483-
self.__root.setAttributeNode(self.__createAttribute(XMLNS_ATTR,NAME_SPACE_ATTR))
484-
self.__root.setAttributeNode(self.__createAttribute(SCHEME_NAME_ATTR,SCHEME_NAME))
485-
self.__doc.appendChild(self.__root)
484+
self.__outputFile = conf.xmlFile
485+
self.__root = None
486+
487+
if os.path.exists(self.__outputFile):
488+
try:
489+
self.__doc = xml.dom.minidom.parse(self.__outputFile)
490+
self.__root = self.__doc.childNodes[0]
491+
except ExpatError:
492+
pass
493+
494+
self.__outputFP = codecs.open(self.__outputFile, "w+", conf.dataEncoding)
495+
496+
if self.__root is None:
497+
self.__root = self.__doc.createElementNS(NAME_SPACE_ATTR, RESULTS_ELEM_NAME)
498+
self.__root.setAttributeNode(self.__createAttribute(XMLNS_ATTR,NAME_SPACE_ATTR))
499+
self.__root.setAttributeNode(self.__createAttribute(SCHEME_NAME_ATTR,SCHEME_NAME))
500+
self.__doc.appendChild(self.__root)
486501
except IOError, e:
487502
raise sqlmapFilePathException("Wrong filename provided for saving the xml file: %s" % conf.xmlFile)
488503

@@ -509,7 +524,8 @@ def finish(self, resultStatus, resultMsg=""):
509524
statusElem.appendChild(errorElem)
510525

511526
self.__addToRoot(statusElem)
512-
self.__write(self.__doc.toprettyxml(encoding=conf.dataEncoding))
527+
#self.__write(self.__doc.toprettyxml(encoding=conf.dataEncoding)) ##don't use toprettyxml, lots of bugs with it
528+
self.__write(self.__doc.toxml(encoding=conf.dataEncoding)) ##not human readable, but at least without bugs
513529
self.__outputFP.close()
514530

515531
def closeDumper(status, msg=""):

0 commit comments

Comments
 (0)