You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by "Hallmark, Brent A" <br...@boeing.com> on 2004/09/30 09:39:46 UTC

Crashing on domBuilder and domDoc 'release'

I have spent several hours trying to figure out why I can't 'release' my
domDoc. Hoping someone can give me some direction. I am a novice with
XML.

I am running on Windows 2000 using VC++6 and xerces2.5 with schema
generated code from XMLSpy.


Here is the significant code:
//************************************************
//Delete the XERCES objects created during the call to parseXMLbuffer.
//************************************************
void parseXMLbufferDelete(CNode *pNode)
{
   static char *funcName="parseXMLbufferDelete";

   poIt = parserObjs.begin();
   
   while (poIt->node0 != pNode && poIt != parserObjs.end())
   {
      poIt++;
   }

   if (poIt != parserObjs.end())
   {

      //Note: Tried reverse order and still does not work.
      //
     delete poIt->xercesInputSource0; //check
      poIt->domSource0->release();     //check
      xercesc::XMLString::release(&poIt->bfrId0); //check

      //NOTE: Leaking about 70 bytes per message w/o the release.
      //

//@@@@@ CRASHING HERE @@@@@
//
poIt->domBuilder0->release();  		//checked; will not work
	   //poIt->domDoc0->release();    //checked; will not work

      parserObjs.erase(poIt);
   }
   else
   {
      cout << "...parserObjs end found." << endl;
   }
}

//************************************************
//************************************************
CNode* parseXMLbuffer(
                      SchemaEnum   	schemaEn, 
                      CDoc       	& doc, 
                      const char 	* data,
                      int          		dataLen) 
{
   static char       *funcName   = "parseXMLbuffer";
   static ushort     msgCt       = msgCt + 1;

   ParserObjectsT po;
   
   memset(&po, 0, sizeof(po));


   //Create a Document object based on the type of XML message.
   //
   try 
   {

      //Create a Document object based on the type of XML message.
      //
      //xx doc0 = (CDoc*)createSchemaObject(schemaEn);



 
//----------------------------------------------------------------------
-----------------------------
   	// The following lines including the line containing 
	// "domBuilder->parse" are required to generate a DOM document
	// from the InformationObject received through the subscription.
	// Apparently the XMLSPY generated data structure can be loaded
	// by simply constructing the root object from a DOM document.
	// This was done because altova::CDoc doesn't provide a Load
	// method that takes a memory buffer as input.  The only Load
	// method provided takes a URI as input.
	// See the implementation of altova::CDoc::Load.
	   

      po.bfrId0 = xercesc::XMLString::transcode(tdl::itoa(msgCt));

	   // Load buffer into an object supporting the SAX InputSource
	   // interface
	   po.xercesInputSource0 = new 
		   xercesc::MemBufInputSource ( (Byte*)data, dataLen,
po.bfrId0 );

	   // Wrap the object supporting the SAX InputSource interface
	   // with an object supporting the DOMInputSource interface
	   po.domSource0 = new
xercesc::Wrapper4InputSource(po.xercesInputSource0, false);


      po.domBuilder0 = doc.GetBuilder();

	   // Parse the received XML message and create a DOMDocument.
	   // Then, load the XMLSPY generated data structure.
	   po.domDoc0 = po.domBuilder0->parse(*po.domSource0);

      //RETURN VARIABLE
      //
      po.node0 = (CNode*)createSchemaObject(schemaEn, po.domDoc0);

      parserObjs.push_back(po);

   } catch (StreamClosedException* /* sce */) {
	   //cout << "Stream Closed!" << endl;
   } catch (Exception *ex) {
	   ex->printStackTrace();
   }

   return po.node0;

} //end parseXMLbuffer()


Thanks in advance,
Brent


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org


Re: Crashing on domBuilder and domDoc 'release'

Posted by Vitaly Prapirny <ma...@mebius.net>.
Hi,
Hallmark, Brent A wrote:
> I have spent several hours trying to figure out why I can't 'release' my
> domDoc. Hoping someone can give me some direction. I am a novice with
> XML.
Seems that parser was deleted after parsing so document was deleted also 
(see the comment for parse in dom\DOMBuilder.hpp).
You could try the following code before parsing:
po.domBuilder0->setFeature(XMLUni::fgXercesUserAdoptsDOMDocument, true);

Good luck !


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org