DWORD XML::writeToFile(xercesc::DOMDocument*
document)
{
DWORD
status = ERROR_SUCCESS;
if
(document == NULL)
return
ERROR_INVALID_HANDLE;
XMLCh tempStr[100];
XMLString::transcode("LS", tempStr, 99);
DOMImplementation
*impl = DOMImplementationRegistry::getDOMImplementation(tempStr);
DOMWriter*
theSerializer = ((DOMImplementationLS*)impl)->createDOMWriter();
XMLCh* utf16str =
NULL;
const XMLByte* str =
NULL;
// optionally you can
set some features on this serializer
if
(theSerializer->canSetFeature(XMLUni::fgDOMWRTDiscardDefaultContent,
true))
theSerializer->setFeature(XMLUni::fgDOMWRTDiscardDefaultContent, true);
if
(theSerializer->canSetFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true))
theSerializer->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true);
LocalFileFormatTarget
myFileTarget( m_xmlFileName );
try
{
theSerializer->writeNode( &myFileTarget, *document);
}
catch (const
XMLException& toCatch)
{
status
= ERROR_CANTWRITE;
}
catch (const
DOMException& toCatch)
{
status
= ERROR_CANTWRITE;
}
catch (...)
{
status
= ERROR_CANTWRITE;
}
theSerializer->release();
return
status;
}
|