I have the following function that I wrote to create an XML file using Xerces 3.0.1, if I call this function with filePath from "foo.xml" or "../foo.xml", it works fine, but if I go to "c: /foo.xml", then I get an exception on this line
XMLFormatTarget *formatTarget = new LocalFileFormatTarget(targetPath);
Can someone explain why my code works for relative paths, but not for absolute paths? many thanks.
const int ABSOLUTE_PATH_FILENAME_PREFIX_SIZE = 9;
void OutputXML(xercesc::DOMDocument* pmyDOMDocument, std::string filePath)
{
DOMImplementation *implementation = DOMImplementationRegistry::getDOMImplementation(L"LS");
DOMLSSerializer *serializer = ((DOMImplementationLS*)implementation)->createLSSerializer();
if (serializer->getDomConfig()->canSetParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true))
serializer->getDomConfig()->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true);
serializer->setNewLine(XMLString::transcode("\r\n"));
XMLCh *tempFilePath = XMLString::transcode(filePath.c_str());
const int pathLen = XMLString::stringLen(tempFilePath);
XMLCh *targetPath = (XMLCh*)XMLPlatformUtils::fgMemoryManager->allocate((pathLen + ABSOLUTE_PATH_FILENAME_PREFIX_SIZE) * sizeof(XMLCh));
XMLString::fixURI(tempFilePath, targetPath);
XMLFormatTarget *formatTarget = new LocalFileFormatTarget(targetPath);
DOMLSOutput *output = ((DOMImplementationLS*)implementation)->createLSOutput();
output->setByteStream(formatTarget);
serializer->write(pmyDOMDocument, output);
serializer->release();
XMLString::release(&tempFilePath);
delete formatTarget;
output->release();
}
source
share