From 7ad0b10132e92598e5dcf1085be92e64b792079e Mon Sep 17 00:00:00 2001 From: Fons Rademakers <Fons.Rademakers@cern.ch> Date: Fri, 2 May 2008 11:12:04 +0000 Subject: [PATCH] fix the TDOMParser to set the new error code -6 in case the XML document is not valid. git-svn-id: http://root.cern.ch/svn/root/trunk@23637 27541ba8-7e3a-0410-8455-c3a389f83636 --- io/xmlparser/inc/TDOMParser.h | 5 ++--- io/xmlparser/src/TDOMParser.cxx | 33 ++++++++++++++++++++++++++------- io/xmlparser/src/TXMLParser.cxx | 5 ++++- 3 files changed, 32 insertions(+), 11 deletions(-) diff --git a/io/xmlparser/inc/TDOMParser.h b/io/xmlparser/inc/TDOMParser.h index f323ae7fc85..9ebe0d25283 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 0e62f14621c..6009b5b1372 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 4c7ed555981..3de15cec7f4 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"; } } -- GitLab