11#!/usr/bin/env python
22
33import codecs
4+ import os
45import re
6+ import xml
57
68import xml .sax .saxutils as saxutils
9+
710from xml .dom .minidom import Document
11+ from xml .parsers .expat import ExpatError
812
913from lib .core .common import getUnicode
1014from 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
515531def closeDumper (status , msg = "" ):
0 commit comments