diff --git a/io/xmlparser/inc/TDOMParser.h b/io/xmlparser/inc/TDOMParser.h
index f323ae7fc858c26e7f5dfc71527ba58a76df97e7..9ebe0d252831da7235cd8a7fee771bca6e427efc 100644
--- a/io/xmlparser/inc/TDOMParser.h
+++ b/io/xmlparser/inc/TDOMParser.h
@@ -38,11 +38,10 @@
 class TDOMParser : public TXMLParser {
 
 private:
-   TDOMParser(const TDOMParser&);            // Not implemented
-   TDOMParser& operator=(const TDOMParser&); // Not implemented
-
    TXMLDocument *fTXMLDoc;      // xmlDoc
 
+   TDOMParser(const TDOMParser&);            // Not implemented
+   TDOMParser& operator=(const TDOMParser&); // Not implemented
    Int_t ParseContext();
 
 public:
diff --git a/io/xmlparser/src/TDOMParser.cxx b/io/xmlparser/src/TDOMParser.cxx
index 0e62f14621c3e19365c9b88dbd0e4999d54178e0..6009b5b13721e74cbfe4847252c65ab29fa82817 100644
--- a/io/xmlparser/src/TDOMParser.cxx
+++ b/io/xmlparser/src/TDOMParser.cxx
@@ -51,8 +51,12 @@ void TDOMParser::ReleaseUnderlying()
 {
    // Release any existing document.
 
-   if (fTXMLDoc)
+   if (fTXMLDoc) {
       delete fTXMLDoc;
+      fTXMLDoc = 0;
+   }
+
+   SetParseCode(0);
 
    TXMLParser::ReleaseUnderlying();
 }
@@ -69,8 +73,10 @@ Int_t TDOMParser::ParseFile(const char *filename)
 
    fContext = xmlCreateFileParserCtxt(filename);
 
-   if (!fContext)
+   if (!fContext) {
+      SetParseCode(-2);
       return -2;
+   }
 
    InitializeContext();
 
@@ -91,8 +97,10 @@ Int_t TDOMParser::ParseBuffer(const char *buffer, Int_t len)
 
    fContext = xmlCreateMemoryParserCtxt(buffer, len);
 
-   if (!fContext)
+   if (!fContext) {
+      SetParseCode(-2);
       return -2;
+   }
 
    InitializeContext();
 
@@ -103,16 +111,27 @@ Int_t TDOMParser::ParseBuffer(const char *buffer, Int_t len)
 Int_t TDOMParser::ParseContext()
 {
    // Creates a XML document for the parser.
-   // It returns 0 on success, -1 if no XML document was created and
-   // -5 if the document is not well formated.
+   // It returns 0 on success, and
+   // -1 if no XML document was created,
+   // -5 if the document is not well formated,
+   // -6 if document is not valid.
 
    xmlParseDocument(fContext);
 
-   if (!fContext->myDoc)
+   if (!fContext->myDoc) {
+      SetParseCode(-1);
       return -1;
+   }
 
-   if (!fContext->wellFormed)
+   if (!fContext->wellFormed) {
+      SetParseCode(-5);
       return -5;
+   }
+
+   if (!fContext->valid) {
+      SetParseCode(-6);
+      return -6;
+   }
 
    fTXMLDoc = new TXMLDocument(fContext->myDoc);
 
diff --git a/io/xmlparser/src/TXMLParser.cxx b/io/xmlparser/src/TXMLParser.cxx
index 4c7ed55598172f07c6c571a4296b3e833b45defb..3de15cec7f4142714744d63bf4a0c251a1834939 100644
--- a/io/xmlparser/src/TXMLParser.cxx
+++ b/io/xmlparser/src/TXMLParser.cxx
@@ -125,8 +125,11 @@ const char *TXMLParser::GetParseCodeMessage(Int_t parseCode) const
       case -5:
          return "Document is not well-formed";
          break;
+      case -6:
+         return "Document is not valid";
+         break;
       default:
-         return "Parse code not exists";
+         return "Parse code does not exist";
    }
 }