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 "Pranav, Savkur" <Pr...@siemens.com> on 2006/10/17 14:50:28 UTC

Issues with DOMWriter::writeToString

Hello,
	We're using the writeToString API of DOMWriter to get back the
XML String when a root node is given.
Following is a code snippet:

ReadXMLNode(const XERCES_CPP_NAMESPACE::DOMNode *const p_pDOMNode)
{
	TRACE_INFO("Entering XH_DOMTreeHelper::ReadXMLNode()");

	SIFRetCode sifRetCode = ERR_FAILURE;

	CString strRetVal;
	
	//Validate the input parameters
	if(0 == p_pDOMNode)
	{
		TRACE_ERROR("ERROR: Given Node is NULL,hence
ERR_INCORRECT_PARAMS is returned",ERR_INCORRECT_PARAMS);
		TRACE_INFO("Leaving XH_DOMTreeHelper::SaveXMLNode()");
		return ERR_INCORRECT_PARAMS;
	}

	bool bIsFormatPrettyPrintNeeded = true;
	XERCES_CPP_NAMESPACE::DOMWriter         *pSerializer = 0;
	try
	{
		// get a serializer, an instance of DOMWriter		
		XMLCh tempStr[100];
		XERCES_CPP_NAMESPACE::XMLString::transcode("LS",
tempStr, 99);

		XERCES_CPP_NAMESPACE::DOMImplementation *impl          =
XERCES_CPP_NAMESPACE::DOMImplementationRegistry::getDOMImplementation(te
mpStr);

		pSerializer =
((XERCES_CPP_NAMESPACE::DOMImplementationLS*)impl)->createDOMWriter();


		if(0 == pSerializer)
		{
			TRACE_ERROR("ERROR: Internal DOM Error. -
createDOMWriter failed",ERR_DOM_OPERATION_FAILED);
			TRACE_INFO("Leaving
XH_DOMTreeHelper::ReadXMLNode()");
			return ERR_DOM_OPERATION_FAILED;
		}	
		strRetVal = pSerializer->writeToString(*p_pDOMNode);
		delete pSerializer;
		pSerializer = 0;
	}

	catch (XERCES_CPP_NAMESPACE::XMLException& e)
	{
		TRACE_INFO("Caught an exception in
XH_DOMTreeHelper::ReadXMLNode()");
		CString cstrTraceMsg;
		cstrTraceMsg.Format(_T("ERROR: Internal DOM Error - An
error occurred during creation of output transcoder. Exception code: %d
Msg is : %s"), e.getCode(),e.getMessage());		
	
TRACE_ERROR(CLString(cstrTraceMsg),ERR_DOM_OPERATION_FAILED);

		delete pSerializer;
		pSerializer = 0;	

		sifRetCode = ERR_DOM_OPERATION_FAILED;
	}
	catch(...)
	{
		TRACE_INFO("Caught an exception in
XH_DOMTreeHelper::ReadXMLNode()");

		delete pSerializer;
		pSerializer = 0;
	
		sifRetCode = ERR_DOM_OPERATION_FAILED;
	}	
	TRACE_INFO("Leaving XH_DOMTreeHelper::ReadXMLNode()");
	return strRetVal;
}

Is this code correct?Must the memory allocated to the tempstr in :
"XMLCh tempStr[100];" be increased if the string to be returned is a
longer string?
Are the getDOMImplementation,createDOMWriter and writeToString methods
threadsafe?

Pls reply.

Regards,
Pranav



The new company Nokia Siemens Networks is expected to start operations by January 1, 2007, subject to customary regulatory approvals, the completion of standard closing conditions, and the agreement of a number of detailed implementation steps.

Disclaimer:
This e-mail may contain trade secrets or privileged, undisclosed or otherwise confidential information. If you have received this e-mail in error, you are hereby notified that any review, copying or distribution of it is strictly prohibited. Please inform us immediately and destroy the original transmittal. Thank you for your cooperation.