views:

40

answers:

1

The following application gives me an access violation on its first line, whats with that?

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

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

using namespace xercesc;

int main()
{

    XMLCh* path= XMLString::transcode("test.xml"); 

    return 0;
}

[edit] The following code gives me an exception on the XMLFormatTarget line, but if i change the string 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;
}
+1  A: 

The obvious error in your program is that you are not initializing xerces-c before using it.

http://xerces.apache.org/xerces-c/program-2.html

You must call XMLPlatformUtils::Initialize() before making any other calls to xerces-c.

Charles Bailey
Thanks very much Charles, perhaps you would be kind enough to help me with one further query, i have updated my original question with my new problem. Thanks
Gungho
@Tim: As you've already accepted an answer to this question and your new question is substantively different from the original wording, it would make more sense to ask it as a new question.
Charles Bailey
@Charles Bailey, i have asked a new question here http://stackoverflow.com/questions/3091484/exception-in-two-line-xerces-program
Gungho