You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-users@xerces.apache.org by appleGuy <al...@gmail.com> on 2006/12/20 18:04:31 UTC

Error In Code (Sax Parsing)

Hi,

My program generates a runtime error...I went through the debugger & it
seems to break at the parser->parse(XMLfile)

The error is:

Debug Error!....this application has requested the runtime to terminate in
an unusual way

The code with problems:

#include "prjLoad.h"

//DEBUG
#include <iostream>
using namespace std;

//Default Constructor
prjLoad::prjLoad(prjHandler *ptr_tmp): prjHandle(ptr_tmp){
	loadXML_prj("xml_file.xml");
}

//Destructor
prjLoad::~prjLoad(void){
	//Terminate The Dom Session
	XMLPlatformUtils::Terminate();
}

bool prjLoad::loadXML_prj(char *prj_filename){
	//Start XML Xerces Framework
	try {
            XMLPlatformUtils::Initialize();
        }
        catch (const XMLException& toCatch) {
            char* message = XMLString::transcode(toCatch.getMessage());
            cout << "Error during initialization! :\n"
                 << message << "\n";
            XMLString::release(&message);
			return false;
        }

		//Create New Parser (SAX)
        SAXParser* parser = new SAXParser();

		//File Input Validation
        parser->setDoValidation(true);    
        parser->setDoNamespaces(true);   

		//Create our SAX handler object and install it on the parser (Doc & Error
Handler)
		//Using Project as Handler
		parser->setDocumentHandler(prjHandle);
		parser->setErrorHandler(prjHandle);

		//Load File through Xerces
		XERCES_STD_QUALIFIER ifstream xmlFileHandle;
        xmlFileHandle.open(prj_filename);

		//Load Each Line From File To Array xmlFile
		bool flag = true;
		while (flag == true)
    {
        char token[1000];
        //Set array to zeros
        memset(token,0,sizeof(token));

		//Sequential Search
		if(!(xmlFileHandle.eof())){
			xmlFileHandle.getline(token, sizeof(token));

			//Check If Line Contains Anything
			if(!(token))
				continue;
			else {
				//Load into New Derived Variable for overloading & Safety
				const char *XMLfile = token;

				//Debug
				cout << "Parsing: " << XMLfile << endl;

				//ERROR WIPE -> NEEDS IMPLIMENTING

				try {
					parser->parse(XMLfile);
				}
				catch(XMLException &e){
					cout << "ERROR OCCURED" << endl;
				}

			}
			
		
		}
		//ELSE STATEMENT FOR EOF-> Set Flag to false therefore exiting while loop
		else
			flag = false;


	}
		return true;
}

Thanks For looking at this its been bugging me for hours

Cheers
-Alex
-- 
View this message in context: http://www.nabble.com/Error-In-Code-%28Sax-Parsing%29-tf2860959.html#a7993779
Sent from the Xerces - C - Users mailing list archive at Nabble.com.


Re: Error In Code (Sax Parsing)

Posted by Ivan Bogouchev <iv...@gmail.com>.
Hello,


On 12/20/06, appleGuy <al...@gmail.com> wrote:[snip]
 ...

>
>                         else {
>                                 //Load into New Derived Variable for
> overloading & Safety
>                                 const char *XMLfile = token;
>
>                                 //Debug
>                                 cout << "Parsing: " << XMLfile << endl;
>
>                                 //ERROR WIPE -> NEEDS IMPLIMENTING
>
>                                 try {
>                                         parser->parse(XMLfile);



The argument to the parse method is the _path_ to the file you want to
parse, but looking at your code it seems to me that you expect it to be the
contents...

Try to removing the while loop and just call  parser->parse("xml_file.xml")
...

Hope it helps


-- 
Ivan

Re: Error In Code (Sax Parsing)

Posted by David Bertoni <db...@apache.org>.
appleGuy wrote:
> Guys,
> 
> Ive got no idea, I really need help & the deadline is looming.
> 
> Please can I have your help?

Yes, but relying on the list to conform to your deadline is probably not a 
good idea, because people may or may not have time to respond.

> 
> Cheers
> Alex
> 
> 
> appleGuy wrote:
>> Hi,
>> Ok...I think ive found the problem. Its to do with memory!
>>
>>
>> On debugging it seems to break on:
>>
>> void* MemoryManagerImpl::allocate(size_t size)
>> {
>>     void* memptr;
>>     try {
>>         memptr = ::operator new(size);
>>
>> My debugger breaks ar memptr..

Does it break at the definition of memptr, or the call to ::operator new()? 
  What is the call stack?

>>
>> Hmm...Ive honestly got no idea how to fix this
>>
>> -Alex
>>
>>
>> appleGuy wrote:
>>> Ok, Ill see what turns up.
>>>
>>> Most (if not all) of the parsing code is not in the constructor. Its in a
>>> seperate function, that is independant of the constructor.
>>>
>>> Cheers
>>> Alex
>>>
>>>
>>> Jesse Pelton wrote:
>>>> You might want to start by trapping all the exceptions that parse() can
>>>> generate.  DOMException, OutOfMemoryException, and (I think)
>>>> SAXException are all possibilities that you haven't covered.  Using the
>>>> getMessage() member to display the exception message may well be
>>>> revealing.
>>>>
>>>> Personally, I'd think twice before implementing a constructor that does
>>>> so much work.  Handling exceptions properly in constructors is
>>>> notoriously difficult, and this one is rife with opportunities for
>>>> error.
>>>>
>>>> -----Original Message-----
>>>> From: appleGuy [mailto:alx.curtis@gmail.com] 
>>>> Sent: Wednesday, December 20, 2006 12:05 PM
>>>> To: c-users@xerces.apache.org
>>>> Subject: Error In Code (Sax Parsing)
>>>>
>>>>
>>>> Hi,
>>>>
>>>> My program generates a runtime error...I went through the debugger & it
>>>> seems to break at the parser->parse(XMLfile)
>>>>
>>>> The error is:
>>>>
>>>> Debug Error!....this application has requested the runtime to terminate
>>>> in
>>>> an unusual way
>>>>
>>>> The code with problems:
>>>>
>>>> #include "prjLoad.h"
>>>>
>>>> //DEBUG
>>>> #include <iostream>
>>>> using namespace std;
>>>>
>>>> //Default Constructor
>>>> prjLoad::prjLoad(prjHandler *ptr_tmp): prjHandle(ptr_tmp){
>>>> 	loadXML_prj("xml_file.xml");
>>>> }
>>>>
>>>> //Destructor
>>>> prjLoad::~prjLoad(void){
>>>> 	//Terminate The Dom Session
>>>> 	XMLPlatformUtils::Terminate();
>>>> }
>>>>

The use of void in the parameter list of your constructor is an anachronism 
left over from C code, and is not necessary.

Note that if you construct an instance of your object, then neglect to call 
prjLoad::loadXML_prj(), then you cannot call XMLPlatformUtils::Terminate() 
in the constructor.  It would be better if you called initialization in 
your constructor.  Or, better yet, if you called 
XMLPlatformUtils::Initialize() _once_ when your executable starts, and 
XMLPlatformUtils::Terminate() _once_ when your executable exits.

>>>> bool prjLoad::loadXML_prj(char *prj_filename){
>>>> 	//Start XML Xerces Framework
>>>> 	try {
>>>>             XMLPlatformUtils::Initialize();
>>>>         }
>>>>         catch (const XMLException& toCatch) {
>>>>             char* message = XMLString::transcode(toCatch.getMessage());
>>>>             cout << "Error during initialization! :\n"
>>>>                  << message << "\n";
>>>>             XMLString::release(&message);
>>>> 			return false;
>>>>         }

Calling XMLString::transcode() when XMLPlatformUtils::Initialize() fails 
will not work.  You cannot call any Xerces-C APIs if initialization fails.

Dave

RE: Error In Code (Sax Parsing)

Posted by appleGuy <al...@gmail.com>.
Guys,

Ive got no idea, I really need help & the deadline is looming.

Please can I have your help?

Cheers
Alex


appleGuy wrote:
> 
> Hi,
> Ok...I think ive found the problem. Its to do with memory!
> 
> 
> On debugging it seems to break on:
> 
> void* MemoryManagerImpl::allocate(size_t size)
> {
>     void* memptr;
>     try {
>         memptr = ::operator new(size);
> 
> My debugger breaks ar memptr..
> 
> Hmm...Ive honestly got no idea how to fix this
> 
> -Alex
> 
> 
> appleGuy wrote:
>> 
>> Ok, Ill see what turns up.
>> 
>> Most (if not all) of the parsing code is not in the constructor. Its in a
>> seperate function, that is independant of the constructor.
>> 
>> Cheers
>> Alex
>> 
>> 
>> Jesse Pelton wrote:
>>> 
>>> You might want to start by trapping all the exceptions that parse() can
>>> generate.  DOMException, OutOfMemoryException, and (I think)
>>> SAXException are all possibilities that you haven't covered.  Using the
>>> getMessage() member to display the exception message may well be
>>> revealing.
>>> 
>>> Personally, I'd think twice before implementing a constructor that does
>>> so much work.  Handling exceptions properly in constructors is
>>> notoriously difficult, and this one is rife with opportunities for
>>> error.
>>> 
>>> -----Original Message-----
>>> From: appleGuy [mailto:alx.curtis@gmail.com] 
>>> Sent: Wednesday, December 20, 2006 12:05 PM
>>> To: c-users@xerces.apache.org
>>> Subject: Error In Code (Sax Parsing)
>>> 
>>> 
>>> Hi,
>>> 
>>> My program generates a runtime error...I went through the debugger & it
>>> seems to break at the parser->parse(XMLfile)
>>> 
>>> The error is:
>>> 
>>> Debug Error!....this application has requested the runtime to terminate
>>> in
>>> an unusual way
>>> 
>>> The code with problems:
>>> 
>>> #include "prjLoad.h"
>>> 
>>> //DEBUG
>>> #include <iostream>
>>> using namespace std;
>>> 
>>> //Default Constructor
>>> prjLoad::prjLoad(prjHandler *ptr_tmp): prjHandle(ptr_tmp){
>>> 	loadXML_prj("xml_file.xml");
>>> }
>>> 
>>> //Destructor
>>> prjLoad::~prjLoad(void){
>>> 	//Terminate The Dom Session
>>> 	XMLPlatformUtils::Terminate();
>>> }
>>> 
>>> bool prjLoad::loadXML_prj(char *prj_filename){
>>> 	//Start XML Xerces Framework
>>> 	try {
>>>             XMLPlatformUtils::Initialize();
>>>         }
>>>         catch (const XMLException& toCatch) {
>>>             char* message = XMLString::transcode(toCatch.getMessage());
>>>             cout << "Error during initialization! :\n"
>>>                  << message << "\n";
>>>             XMLString::release(&message);
>>> 			return false;
>>>         }
>>> 
>>> 		//Create New Parser (SAX)
>>>         SAXParser* parser = new SAXParser();
>>> 
>>> 		//File Input Validation
>>>         parser->setDoValidation(true);    
>>>         parser->setDoNamespaces(true);   
>>> 
>>> 		//Create our SAX handler object and install it on the
>>> parser (Doc & Error
>>> Handler)
>>> 		//Using Project as Handler
>>> 		parser->setDocumentHandler(prjHandle);
>>> 		parser->setErrorHandler(prjHandle);
>>> 
>>> 		//Load File through Xerces
>>> 		XERCES_STD_QUALIFIER ifstream xmlFileHandle;
>>>         xmlFileHandle.open(prj_filename);
>>> 
>>> 		//Load Each Line From File To Array xmlFile
>>> 		bool flag = true;
>>> 		while (flag == true)
>>>     {
>>>         char token[1000];
>>>         //Set array to zeros
>>>         memset(token,0,sizeof(token));
>>> 
>>> 		//Sequential Search
>>> 		if(!(xmlFileHandle.eof())){
>>> 			xmlFileHandle.getline(token, sizeof(token));
>>> 
>>> 			//Check If Line Contains Anything
>>> 			if(!(token))
>>> 				continue;
>>> 			else {
>>> 				//Load into New Derived Variable for
>>> overloading & Safety
>>> 				const char *XMLfile = token;
>>> 
>>> 				//Debug
>>> 				cout << "Parsing: " << XMLfile << endl;
>>> 
>>> 				//ERROR WIPE -> NEEDS IMPLIMENTING
>>> 
>>> 				try {
>>> 					parser->parse(XMLfile);
>>> 				}
>>> 				catch(XMLException &e){
>>> 					cout << "ERROR OCCURED" << endl;
>>> 				}
>>> 
>>> 			}
>>> 			
>>> 		
>>> 		}
>>> 		//ELSE STATEMENT FOR EOF-> Set Flag to false therefore
>>> exiting while loop
>>> 		else
>>> 			flag = false;
>>> 
>>> 
>>> 	}
>>> 		return true;
>>> }
>>> 
>>> Thanks For looking at this its been bugging me for hours
>>> 
>>> Cheers
>>> -Alex
>>> -- 
>>> View this message in context:
>>> http://www.nabble.com/Error-In-Code-%28Sax-Parsing%29-tf2860959.html#a79
>>> 93779
>>> Sent from the Xerces - C - Users mailing list archive at Nabble.com.
>>> 
>>> 
>>> 
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Error-In-Code-%28Sax-Parsing%29-tf2860959.html#a8000110
Sent from the Xerces - C - Users mailing list archive at Nabble.com.


RE: Error In Code (Sax Parsing)

Posted by appleGuy <al...@gmail.com>.
Hi,
Ok...I think ive found the problem. Its to do with memory!


On debugging it seems to break on:

void* MemoryManagerImpl::allocate(size_t size)
{
    void* memptr;
    try {
        memptr = ::operator new(size);

My debugger breaks ar memptr..

Hmm...Ive honestly got no idea how to fix this

-Alex


appleGuy wrote:
> 
> Ok, Ill see what turns up.
> 
> Most (if not all) of the parsing code is not in the constructor. Its in a
> seperate function, that is independant of the constructor.
> 
> Cheers
> Alex
> 
> 
> Jesse Pelton wrote:
>> 
>> You might want to start by trapping all the exceptions that parse() can
>> generate.  DOMException, OutOfMemoryException, and (I think)
>> SAXException are all possibilities that you haven't covered.  Using the
>> getMessage() member to display the exception message may well be
>> revealing.
>> 
>> Personally, I'd think twice before implementing a constructor that does
>> so much work.  Handling exceptions properly in constructors is
>> notoriously difficult, and this one is rife with opportunities for
>> error.
>> 
>> -----Original Message-----
>> From: appleGuy [mailto:alx.curtis@gmail.com] 
>> Sent: Wednesday, December 20, 2006 12:05 PM
>> To: c-users@xerces.apache.org
>> Subject: Error In Code (Sax Parsing)
>> 
>> 
>> Hi,
>> 
>> My program generates a runtime error...I went through the debugger & it
>> seems to break at the parser->parse(XMLfile)
>> 
>> The error is:
>> 
>> Debug Error!....this application has requested the runtime to terminate
>> in
>> an unusual way
>> 
>> The code with problems:
>> 
>> #include "prjLoad.h"
>> 
>> //DEBUG
>> #include <iostream>
>> using namespace std;
>> 
>> //Default Constructor
>> prjLoad::prjLoad(prjHandler *ptr_tmp): prjHandle(ptr_tmp){
>> 	loadXML_prj("xml_file.xml");
>> }
>> 
>> //Destructor
>> prjLoad::~prjLoad(void){
>> 	//Terminate The Dom Session
>> 	XMLPlatformUtils::Terminate();
>> }
>> 
>> bool prjLoad::loadXML_prj(char *prj_filename){
>> 	//Start XML Xerces Framework
>> 	try {
>>             XMLPlatformUtils::Initialize();
>>         }
>>         catch (const XMLException& toCatch) {
>>             char* message = XMLString::transcode(toCatch.getMessage());
>>             cout << "Error during initialization! :\n"
>>                  << message << "\n";
>>             XMLString::release(&message);
>> 			return false;
>>         }
>> 
>> 		//Create New Parser (SAX)
>>         SAXParser* parser = new SAXParser();
>> 
>> 		//File Input Validation
>>         parser->setDoValidation(true);    
>>         parser->setDoNamespaces(true);   
>> 
>> 		//Create our SAX handler object and install it on the
>> parser (Doc & Error
>> Handler)
>> 		//Using Project as Handler
>> 		parser->setDocumentHandler(prjHandle);
>> 		parser->setErrorHandler(prjHandle);
>> 
>> 		//Load File through Xerces
>> 		XERCES_STD_QUALIFIER ifstream xmlFileHandle;
>>         xmlFileHandle.open(prj_filename);
>> 
>> 		//Load Each Line From File To Array xmlFile
>> 		bool flag = true;
>> 		while (flag == true)
>>     {
>>         char token[1000];
>>         //Set array to zeros
>>         memset(token,0,sizeof(token));
>> 
>> 		//Sequential Search
>> 		if(!(xmlFileHandle.eof())){
>> 			xmlFileHandle.getline(token, sizeof(token));
>> 
>> 			//Check If Line Contains Anything
>> 			if(!(token))
>> 				continue;
>> 			else {
>> 				//Load into New Derived Variable for
>> overloading & Safety
>> 				const char *XMLfile = token;
>> 
>> 				//Debug
>> 				cout << "Parsing: " << XMLfile << endl;
>> 
>> 				//ERROR WIPE -> NEEDS IMPLIMENTING
>> 
>> 				try {
>> 					parser->parse(XMLfile);
>> 				}
>> 				catch(XMLException &e){
>> 					cout << "ERROR OCCURED" << endl;
>> 				}
>> 
>> 			}
>> 			
>> 		
>> 		}
>> 		//ELSE STATEMENT FOR EOF-> Set Flag to false therefore
>> exiting while loop
>> 		else
>> 			flag = false;
>> 
>> 
>> 	}
>> 		return true;
>> }
>> 
>> Thanks For looking at this its been bugging me for hours
>> 
>> Cheers
>> -Alex
>> -- 
>> View this message in context:
>> http://www.nabble.com/Error-In-Code-%28Sax-Parsing%29-tf2860959.html#a79
>> 93779
>> Sent from the Xerces - C - Users mailing list archive at Nabble.com.
>> 
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Error-In-Code-%28Sax-Parsing%29-tf2860959.html#a7994656
Sent from the Xerces - C - Users mailing list archive at Nabble.com.


RE: Error In Code (Sax Parsing)

Posted by Jesse Pelton <js...@PKC.com>.
Would you be willing to say what the problem was?  It might help people
who search the archives in the future.  (Besides, I'm curious.) 

-----Original Message-----
From: appleGuy [mailto:alx.curtis@gmail.com] 
Sent: Thursday, December 21, 2006 7:39 PM
To: c-users@xerces.apache.org
Subject: RE: Error In Code (Sax Parsing)


Ok Guys,

Ive sorted It & made my deadline..

Thankyou to everyone who helped

Cheers
Alex


Jesse Pelton wrote:
> 
> But your constructor calls loadXML_proj(), so all the code in that
> function is executed while prjLoad is being constructed.  This does
not
> differ in any significant way from executing the same code in the
> constructor.  
> 
> -----Original Message-----
> From: appleGuy [mailto:alx.curtis@gmail.com] 
> Sent: Wednesday, December 20, 2006 12:32 PM
> To: c-users@xerces.apache.org
> Subject: RE: Error In Code (Sax Parsing)
> 
> 
> Ok, Ill see what turns up.
> 
> Most (if not all) of the parsing code is not in the constructor. Its
in
> a
> seperate function, that is independant of the constructor.
> 
> Cheers
> Alex
> 
> 
> Jesse Pelton wrote:
>> 
>> You might want to start by trapping all the exceptions that parse()
> can
>> generate.  DOMException, OutOfMemoryException, and (I think)
>> SAXException are all possibilities that you haven't covered.  Using
> the
>> getMessage() member to display the exception message may well be
>> revealing.
>> 
>> Personally, I'd think twice before implementing a constructor that
> does
>> so much work.  Handling exceptions properly in constructors is
>> notoriously difficult, and this one is rife with opportunities for
>> error.
>> 
>> -----Original Message-----
>> From: appleGuy [mailto:alx.curtis@gmail.com] 
>> Sent: Wednesday, December 20, 2006 12:05 PM
>> To: c-users@xerces.apache.org
>> Subject: Error In Code (Sax Parsing)
>> 
>> 
>> Hi,
>> 
>> My program generates a runtime error...I went through the debugger &
> it
>> seems to break at the parser->parse(XMLfile)
>> 
>> The error is:
>> 
>> Debug Error!....this application has requested the runtime to
> terminate
>> in
>> an unusual way
>> 
>> The code with problems:
>> 
>> #include "prjLoad.h"
>> 
>> //DEBUG
>> #include <iostream>
>> using namespace std;
>> 
>> //Default Constructor
>> prjLoad::prjLoad(prjHandler *ptr_tmp): prjHandle(ptr_tmp){
>> 	loadXML_prj("xml_file.xml");
>> }
>> 
>> //Destructor
>> prjLoad::~prjLoad(void){
>> 	//Terminate The Dom Session
>> 	XMLPlatformUtils::Terminate();
>> }
>> 
>> bool prjLoad::loadXML_prj(char *prj_filename){
>> 	//Start XML Xerces Framework
>> 	try {
>>             XMLPlatformUtils::Initialize();
>>         }
>>         catch (const XMLException& toCatch) {
>>             char* message =
> XMLString::transcode(toCatch.getMessage());
>>             cout << "Error during initialization! :\n"
>>                  << message << "\n";
>>             XMLString::release(&message);
>> 			return false;
>>         }
>> 
>> 		//Create New Parser (SAX)
>>         SAXParser* parser = new SAXParser();
>> 
>> 		//File Input Validation
>>         parser->setDoValidation(true);    
>>         parser->setDoNamespaces(true);   
>> 
>> 		//Create our SAX handler object and install it on the
>> parser (Doc & Error
>> Handler)
>> 		//Using Project as Handler
>> 		parser->setDocumentHandler(prjHandle);
>> 		parser->setErrorHandler(prjHandle);
>> 
>> 		//Load File through Xerces
>> 		XERCES_STD_QUALIFIER ifstream xmlFileHandle;
>>         xmlFileHandle.open(prj_filename);
>> 
>> 		//Load Each Line From File To Array xmlFile
>> 		bool flag = true;
>> 		while (flag == true)
>>     {
>>         char token[1000];
>>         //Set array to zeros
>>         memset(token,0,sizeof(token));
>> 
>> 		//Sequential Search
>> 		if(!(xmlFileHandle.eof())){
>> 			xmlFileHandle.getline(token, sizeof(token));
>> 
>> 			//Check If Line Contains Anything
>> 			if(!(token))
>> 				continue;
>> 			else {
>> 				//Load into New Derived Variable for
>> overloading & Safety
>> 				const char *XMLfile = token;
>> 
>> 				//Debug
>> 				cout << "Parsing: " << XMLfile << endl;
>> 
>> 				//ERROR WIPE -> NEEDS IMPLIMENTING
>> 
>> 				try {
>> 					parser->parse(XMLfile);
>> 				}
>> 				catch(XMLException &e){
>> 					cout << "ERROR OCCURED" << endl;
>> 				}
>> 
>> 			}
>> 			
>> 		
>> 		}
>> 		//ELSE STATEMENT FOR EOF-> Set Flag to false therefore
>> exiting while loop
>> 		else
>> 			flag = false;
>> 
>> 
>> 	}
>> 		return true;
>> }
>> 
>> Thanks For looking at this its been bugging me for hours
>> 
>> Cheers
>> -Alex
>> -- 
>> View this message in context:
>>
>
http://www.nabble.com/Error-In-Code-%28Sax-Parsing%29-tf2860959.html#a79
>> 93779
>> Sent from the Xerces - C - Users mailing list archive at Nabble.com.
>> 
>> 
>> 
> 
> -- 
> View this message in context:
>
http://www.nabble.com/Error-In-Code-%28Sax-Parsing%29-tf2860959.html#a79
> 94297
> Sent from the Xerces - C - Users mailing list archive at Nabble.com.
> 
> 
> 

-- 
View this message in context:
http://www.nabble.com/Error-In-Code-%28Sax-Parsing%29-tf2860959.html#a80
17526
Sent from the Xerces - C - Users mailing list archive at Nabble.com.


RE: Error In Code (Sax Parsing)

Posted by appleGuy <al...@gmail.com>.
Ok Guys,

Ive sorted It & made my deadline..

Thankyou to everyone who helped

Cheers
Alex


Jesse Pelton wrote:
> 
> But your constructor calls loadXML_proj(), so all the code in that
> function is executed while prjLoad is being constructed.  This does not
> differ in any significant way from executing the same code in the
> constructor.  
> 
> -----Original Message-----
> From: appleGuy [mailto:alx.curtis@gmail.com] 
> Sent: Wednesday, December 20, 2006 12:32 PM
> To: c-users@xerces.apache.org
> Subject: RE: Error In Code (Sax Parsing)
> 
> 
> Ok, Ill see what turns up.
> 
> Most (if not all) of the parsing code is not in the constructor. Its in
> a
> seperate function, that is independant of the constructor.
> 
> Cheers
> Alex
> 
> 
> Jesse Pelton wrote:
>> 
>> You might want to start by trapping all the exceptions that parse()
> can
>> generate.  DOMException, OutOfMemoryException, and (I think)
>> SAXException are all possibilities that you haven't covered.  Using
> the
>> getMessage() member to display the exception message may well be
>> revealing.
>> 
>> Personally, I'd think twice before implementing a constructor that
> does
>> so much work.  Handling exceptions properly in constructors is
>> notoriously difficult, and this one is rife with opportunities for
>> error.
>> 
>> -----Original Message-----
>> From: appleGuy [mailto:alx.curtis@gmail.com] 
>> Sent: Wednesday, December 20, 2006 12:05 PM
>> To: c-users@xerces.apache.org
>> Subject: Error In Code (Sax Parsing)
>> 
>> 
>> Hi,
>> 
>> My program generates a runtime error...I went through the debugger &
> it
>> seems to break at the parser->parse(XMLfile)
>> 
>> The error is:
>> 
>> Debug Error!....this application has requested the runtime to
> terminate
>> in
>> an unusual way
>> 
>> The code with problems:
>> 
>> #include "prjLoad.h"
>> 
>> //DEBUG
>> #include <iostream>
>> using namespace std;
>> 
>> //Default Constructor
>> prjLoad::prjLoad(prjHandler *ptr_tmp): prjHandle(ptr_tmp){
>> 	loadXML_prj("xml_file.xml");
>> }
>> 
>> //Destructor
>> prjLoad::~prjLoad(void){
>> 	//Terminate The Dom Session
>> 	XMLPlatformUtils::Terminate();
>> }
>> 
>> bool prjLoad::loadXML_prj(char *prj_filename){
>> 	//Start XML Xerces Framework
>> 	try {
>>             XMLPlatformUtils::Initialize();
>>         }
>>         catch (const XMLException& toCatch) {
>>             char* message =
> XMLString::transcode(toCatch.getMessage());
>>             cout << "Error during initialization! :\n"
>>                  << message << "\n";
>>             XMLString::release(&message);
>> 			return false;
>>         }
>> 
>> 		//Create New Parser (SAX)
>>         SAXParser* parser = new SAXParser();
>> 
>> 		//File Input Validation
>>         parser->setDoValidation(true);    
>>         parser->setDoNamespaces(true);   
>> 
>> 		//Create our SAX handler object and install it on the
>> parser (Doc & Error
>> Handler)
>> 		//Using Project as Handler
>> 		parser->setDocumentHandler(prjHandle);
>> 		parser->setErrorHandler(prjHandle);
>> 
>> 		//Load File through Xerces
>> 		XERCES_STD_QUALIFIER ifstream xmlFileHandle;
>>         xmlFileHandle.open(prj_filename);
>> 
>> 		//Load Each Line From File To Array xmlFile
>> 		bool flag = true;
>> 		while (flag == true)
>>     {
>>         char token[1000];
>>         //Set array to zeros
>>         memset(token,0,sizeof(token));
>> 
>> 		//Sequential Search
>> 		if(!(xmlFileHandle.eof())){
>> 			xmlFileHandle.getline(token, sizeof(token));
>> 
>> 			//Check If Line Contains Anything
>> 			if(!(token))
>> 				continue;
>> 			else {
>> 				//Load into New Derived Variable for
>> overloading & Safety
>> 				const char *XMLfile = token;
>> 
>> 				//Debug
>> 				cout << "Parsing: " << XMLfile << endl;
>> 
>> 				//ERROR WIPE -> NEEDS IMPLIMENTING
>> 
>> 				try {
>> 					parser->parse(XMLfile);
>> 				}
>> 				catch(XMLException &e){
>> 					cout << "ERROR OCCURED" << endl;
>> 				}
>> 
>> 			}
>> 			
>> 		
>> 		}
>> 		//ELSE STATEMENT FOR EOF-> Set Flag to false therefore
>> exiting while loop
>> 		else
>> 			flag = false;
>> 
>> 
>> 	}
>> 		return true;
>> }
>> 
>> Thanks For looking at this its been bugging me for hours
>> 
>> Cheers
>> -Alex
>> -- 
>> View this message in context:
>>
> http://www.nabble.com/Error-In-Code-%28Sax-Parsing%29-tf2860959.html#a79
>> 93779
>> Sent from the Xerces - C - Users mailing list archive at Nabble.com.
>> 
>> 
>> 
> 
> -- 
> View this message in context:
> http://www.nabble.com/Error-In-Code-%28Sax-Parsing%29-tf2860959.html#a79
> 94297
> Sent from the Xerces - C - Users mailing list archive at Nabble.com.
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Error-In-Code-%28Sax-Parsing%29-tf2860959.html#a8017526
Sent from the Xerces - C - Users mailing list archive at Nabble.com.


RE: Error In Code (Sax Parsing)

Posted by Jesse Pelton <js...@PKC.com>.
But your constructor calls loadXML_proj(), so all the code in that
function is executed while prjLoad is being constructed.  This does not
differ in any significant way from executing the same code in the
constructor.  

-----Original Message-----
From: appleGuy [mailto:alx.curtis@gmail.com] 
Sent: Wednesday, December 20, 2006 12:32 PM
To: c-users@xerces.apache.org
Subject: RE: Error In Code (Sax Parsing)


Ok, Ill see what turns up.

Most (if not all) of the parsing code is not in the constructor. Its in
a
seperate function, that is independant of the constructor.

Cheers
Alex


Jesse Pelton wrote:
> 
> You might want to start by trapping all the exceptions that parse()
can
> generate.  DOMException, OutOfMemoryException, and (I think)
> SAXException are all possibilities that you haven't covered.  Using
the
> getMessage() member to display the exception message may well be
> revealing.
> 
> Personally, I'd think twice before implementing a constructor that
does
> so much work.  Handling exceptions properly in constructors is
> notoriously difficult, and this one is rife with opportunities for
> error.
> 
> -----Original Message-----
> From: appleGuy [mailto:alx.curtis@gmail.com] 
> Sent: Wednesday, December 20, 2006 12:05 PM
> To: c-users@xerces.apache.org
> Subject: Error In Code (Sax Parsing)
> 
> 
> Hi,
> 
> My program generates a runtime error...I went through the debugger &
it
> seems to break at the parser->parse(XMLfile)
> 
> The error is:
> 
> Debug Error!....this application has requested the runtime to
terminate
> in
> an unusual way
> 
> The code with problems:
> 
> #include "prjLoad.h"
> 
> //DEBUG
> #include <iostream>
> using namespace std;
> 
> //Default Constructor
> prjLoad::prjLoad(prjHandler *ptr_tmp): prjHandle(ptr_tmp){
> 	loadXML_prj("xml_file.xml");
> }
> 
> //Destructor
> prjLoad::~prjLoad(void){
> 	//Terminate The Dom Session
> 	XMLPlatformUtils::Terminate();
> }
> 
> bool prjLoad::loadXML_prj(char *prj_filename){
> 	//Start XML Xerces Framework
> 	try {
>             XMLPlatformUtils::Initialize();
>         }
>         catch (const XMLException& toCatch) {
>             char* message =
XMLString::transcode(toCatch.getMessage());
>             cout << "Error during initialization! :\n"
>                  << message << "\n";
>             XMLString::release(&message);
> 			return false;
>         }
> 
> 		//Create New Parser (SAX)
>         SAXParser* parser = new SAXParser();
> 
> 		//File Input Validation
>         parser->setDoValidation(true);    
>         parser->setDoNamespaces(true);   
> 
> 		//Create our SAX handler object and install it on the
> parser (Doc & Error
> Handler)
> 		//Using Project as Handler
> 		parser->setDocumentHandler(prjHandle);
> 		parser->setErrorHandler(prjHandle);
> 
> 		//Load File through Xerces
> 		XERCES_STD_QUALIFIER ifstream xmlFileHandle;
>         xmlFileHandle.open(prj_filename);
> 
> 		//Load Each Line From File To Array xmlFile
> 		bool flag = true;
> 		while (flag == true)
>     {
>         char token[1000];
>         //Set array to zeros
>         memset(token,0,sizeof(token));
> 
> 		//Sequential Search
> 		if(!(xmlFileHandle.eof())){
> 			xmlFileHandle.getline(token, sizeof(token));
> 
> 			//Check If Line Contains Anything
> 			if(!(token))
> 				continue;
> 			else {
> 				//Load into New Derived Variable for
> overloading & Safety
> 				const char *XMLfile = token;
> 
> 				//Debug
> 				cout << "Parsing: " << XMLfile << endl;
> 
> 				//ERROR WIPE -> NEEDS IMPLIMENTING
> 
> 				try {
> 					parser->parse(XMLfile);
> 				}
> 				catch(XMLException &e){
> 					cout << "ERROR OCCURED" << endl;
> 				}
> 
> 			}
> 			
> 		
> 		}
> 		//ELSE STATEMENT FOR EOF-> Set Flag to false therefore
> exiting while loop
> 		else
> 			flag = false;
> 
> 
> 	}
> 		return true;
> }
> 
> Thanks For looking at this its been bugging me for hours
> 
> Cheers
> -Alex
> -- 
> View this message in context:
>
http://www.nabble.com/Error-In-Code-%28Sax-Parsing%29-tf2860959.html#a79
> 93779
> Sent from the Xerces - C - Users mailing list archive at Nabble.com.
> 
> 
> 

-- 
View this message in context:
http://www.nabble.com/Error-In-Code-%28Sax-Parsing%29-tf2860959.html#a79
94297
Sent from the Xerces - C - Users mailing list archive at Nabble.com.


RE: Error In Code (Sax Parsing)

Posted by appleGuy <al...@gmail.com>.
Ok, Ill see what turns up.

Most (if not all) of the parsing code is not in the constructor. Its in a
seperate function, that is independant of the constructor.

Cheers
Alex


Jesse Pelton wrote:
> 
> You might want to start by trapping all the exceptions that parse() can
> generate.  DOMException, OutOfMemoryException, and (I think)
> SAXException are all possibilities that you haven't covered.  Using the
> getMessage() member to display the exception message may well be
> revealing.
> 
> Personally, I'd think twice before implementing a constructor that does
> so much work.  Handling exceptions properly in constructors is
> notoriously difficult, and this one is rife with opportunities for
> error.
> 
> -----Original Message-----
> From: appleGuy [mailto:alx.curtis@gmail.com] 
> Sent: Wednesday, December 20, 2006 12:05 PM
> To: c-users@xerces.apache.org
> Subject: Error In Code (Sax Parsing)
> 
> 
> Hi,
> 
> My program generates a runtime error...I went through the debugger & it
> seems to break at the parser->parse(XMLfile)
> 
> The error is:
> 
> Debug Error!....this application has requested the runtime to terminate
> in
> an unusual way
> 
> The code with problems:
> 
> #include "prjLoad.h"
> 
> //DEBUG
> #include <iostream>
> using namespace std;
> 
> //Default Constructor
> prjLoad::prjLoad(prjHandler *ptr_tmp): prjHandle(ptr_tmp){
> 	loadXML_prj("xml_file.xml");
> }
> 
> //Destructor
> prjLoad::~prjLoad(void){
> 	//Terminate The Dom Session
> 	XMLPlatformUtils::Terminate();
> }
> 
> bool prjLoad::loadXML_prj(char *prj_filename){
> 	//Start XML Xerces Framework
> 	try {
>             XMLPlatformUtils::Initialize();
>         }
>         catch (const XMLException& toCatch) {
>             char* message = XMLString::transcode(toCatch.getMessage());
>             cout << "Error during initialization! :\n"
>                  << message << "\n";
>             XMLString::release(&message);
> 			return false;
>         }
> 
> 		//Create New Parser (SAX)
>         SAXParser* parser = new SAXParser();
> 
> 		//File Input Validation
>         parser->setDoValidation(true);    
>         parser->setDoNamespaces(true);   
> 
> 		//Create our SAX handler object and install it on the
> parser (Doc & Error
> Handler)
> 		//Using Project as Handler
> 		parser->setDocumentHandler(prjHandle);
> 		parser->setErrorHandler(prjHandle);
> 
> 		//Load File through Xerces
> 		XERCES_STD_QUALIFIER ifstream xmlFileHandle;
>         xmlFileHandle.open(prj_filename);
> 
> 		//Load Each Line From File To Array xmlFile
> 		bool flag = true;
> 		while (flag == true)
>     {
>         char token[1000];
>         //Set array to zeros
>         memset(token,0,sizeof(token));
> 
> 		//Sequential Search
> 		if(!(xmlFileHandle.eof())){
> 			xmlFileHandle.getline(token, sizeof(token));
> 
> 			//Check If Line Contains Anything
> 			if(!(token))
> 				continue;
> 			else {
> 				//Load into New Derived Variable for
> overloading & Safety
> 				const char *XMLfile = token;
> 
> 				//Debug
> 				cout << "Parsing: " << XMLfile << endl;
> 
> 				//ERROR WIPE -> NEEDS IMPLIMENTING
> 
> 				try {
> 					parser->parse(XMLfile);
> 				}
> 				catch(XMLException &e){
> 					cout << "ERROR OCCURED" << endl;
> 				}
> 
> 			}
> 			
> 		
> 		}
> 		//ELSE STATEMENT FOR EOF-> Set Flag to false therefore
> exiting while loop
> 		else
> 			flag = false;
> 
> 
> 	}
> 		return true;
> }
> 
> Thanks For looking at this its been bugging me for hours
> 
> Cheers
> -Alex
> -- 
> View this message in context:
> http://www.nabble.com/Error-In-Code-%28Sax-Parsing%29-tf2860959.html#a79
> 93779
> Sent from the Xerces - C - Users mailing list archive at Nabble.com.
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Error-In-Code-%28Sax-Parsing%29-tf2860959.html#a7994297
Sent from the Xerces - C - Users mailing list archive at Nabble.com.


RE: Error In Code (Sax Parsing)

Posted by Jesse Pelton <js...@PKC.com>.
You might want to start by trapping all the exceptions that parse() can
generate.  DOMException, OutOfMemoryException, and (I think)
SAXException are all possibilities that you haven't covered.  Using the
getMessage() member to display the exception message may well be
revealing.

Personally, I'd think twice before implementing a constructor that does
so much work.  Handling exceptions properly in constructors is
notoriously difficult, and this one is rife with opportunities for
error.

-----Original Message-----
From: appleGuy [mailto:alx.curtis@gmail.com] 
Sent: Wednesday, December 20, 2006 12:05 PM
To: c-users@xerces.apache.org
Subject: Error In Code (Sax Parsing)


Hi,

My program generates a runtime error...I went through the debugger & it
seems to break at the parser->parse(XMLfile)

The error is:

Debug Error!....this application has requested the runtime to terminate
in
an unusual way

The code with problems:

#include "prjLoad.h"

//DEBUG
#include <iostream>
using namespace std;

//Default Constructor
prjLoad::prjLoad(prjHandler *ptr_tmp): prjHandle(ptr_tmp){
	loadXML_prj("xml_file.xml");
}

//Destructor
prjLoad::~prjLoad(void){
	//Terminate The Dom Session
	XMLPlatformUtils::Terminate();
}

bool prjLoad::loadXML_prj(char *prj_filename){
	//Start XML Xerces Framework
	try {
            XMLPlatformUtils::Initialize();
        }
        catch (const XMLException& toCatch) {
            char* message = XMLString::transcode(toCatch.getMessage());
            cout << "Error during initialization! :\n"
                 << message << "\n";
            XMLString::release(&message);
			return false;
        }

		//Create New Parser (SAX)
        SAXParser* parser = new SAXParser();

		//File Input Validation
        parser->setDoValidation(true);    
        parser->setDoNamespaces(true);   

		//Create our SAX handler object and install it on the
parser (Doc & Error
Handler)
		//Using Project as Handler
		parser->setDocumentHandler(prjHandle);
		parser->setErrorHandler(prjHandle);

		//Load File through Xerces
		XERCES_STD_QUALIFIER ifstream xmlFileHandle;
        xmlFileHandle.open(prj_filename);

		//Load Each Line From File To Array xmlFile
		bool flag = true;
		while (flag == true)
    {
        char token[1000];
        //Set array to zeros
        memset(token,0,sizeof(token));

		//Sequential Search
		if(!(xmlFileHandle.eof())){
			xmlFileHandle.getline(token, sizeof(token));

			//Check If Line Contains Anything
			if(!(token))
				continue;
			else {
				//Load into New Derived Variable for
overloading & Safety
				const char *XMLfile = token;

				//Debug
				cout << "Parsing: " << XMLfile << endl;

				//ERROR WIPE -> NEEDS IMPLIMENTING

				try {
					parser->parse(XMLfile);
				}
				catch(XMLException &e){
					cout << "ERROR OCCURED" << endl;
				}

			}
			
		
		}
		//ELSE STATEMENT FOR EOF-> Set Flag to false therefore
exiting while loop
		else
			flag = false;


	}
		return true;
}

Thanks For looking at this its been bugging me for hours

Cheers
-Alex
-- 
View this message in context:
http://www.nabble.com/Error-In-Code-%28Sax-Parsing%29-tf2860959.html#a79
93779
Sent from the Xerces - C - Users mailing list archive at Nabble.com.