Xerces two-line exception

The following code gives me an exception in the line XMLFormatTarget, but if I change the line from "C:/test.xml"to "test.xml", it works fine.

// test.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <xercesc/util/XMLString.hpp>
#include <xercesc/framework/LocalFileFormatTarget.hpp>

using namespace xercesc;

int main()
{
    XMLPlatformUtils::Initialize();

    XMLFormatTarget *formatTarget = new LocalFileFormatTarget("C:/test.xml"); 

    return 0;
}

[edit] Xerces exception:

Error message: cannot open file 'C: \ test.xml'

Windows exception:

Access is denied

0
source share
3 answers

You may not have sufficient permissions to write to C:\. In this case, Xerces may report an error that throws an exception.

The exception is Access Deniedusually what you would expect if you tried to write to the system directory without administrator credentials.


, :

XMLFormatTarget *formatTarget = new LocalFileFormatTarget("C:\\test.xml");

Windows "\". ( Xerces, ). C C++ escape, , , "litteral".

, , , .


, , delete formatTarget. , , , :

delete formatTarget;

:

boost::scoped_ptr<XMLFormatTarget> formatTarget(new LocalFileFormatTarget("C:\\test.xml"));

.

+1

:

// Convert the path into Xerces compatible XMLCh*. 
XMLCh *tempFilePath = XMLString::transcode(filePath.c_str()); 

// Specify the target for the XML output. 
XMLFormatTarget *formatTarget = new LocalFileFormatTarget(tempFilePath);

.

+1

test.xml, ( , ). , C: . C:\test.xml , C:\Path\to\your\program\test.xml , .

, Γ–On, , , .

0

Source: https://habr.com/ru/post/1746867/


All Articles