Calling with xerces

Top  Previous  Next

Code generation > Calling a parser > Calling with xerces

 

If xerces dnodes are used in the project, the code for the call of a parsers must be enlarged. You have to set the options for the xerces DOM manually. Dont't forget to set CTT_ParseStateDomPlugin as plugin in the options for the code generation.

 

 

#ifdef __BORLANDC__

#pragma hdrstop

#endif

 

#include <fstream>

#include "tt_exception.h"

#include "tt_lib.h"

#include "xxxparser.h"

#include <xercesc/dom/DOM.hpp>

#include <xercesc/util/OutOfMemoryException.hpp>

 

 

using namespace std;

using namespace tetra;

 

 

int main(int argc, char* argv[])

{

 

  string sTest;

   

  if(!load_file(sTest, "test.txt"))

  {

     cout << "could not load file: " << "test.txt";

     return 0;

  }

 

 

try

{

ofstream fout("data.xml"); 

CTT_ParseStateDomPlugin<char> plugin(fout);

 

CTT_Xerces Xerces("root",

                  "UTF-8",

                  false, // BOM

                  true,  // Pretty-Print

                  true,  // Write declaration

                  true); // Standalone

/*

Xerces.setDTDParams( ...   // DocTypeName,

                     ...   // PublicID,

                    ... ): // SystemID

*/

 

plugin.SetXerces(&Xerces);

CTT_DomNode::SetDefaultLabel(L"default_label");

 

plugin.SourceName("test.txt");

//plugin.SourceRoot(sSourceDir);

plugin.TargetName("data.xml");

//plugin.TargetRoot(sTargetDir);

 

CXXXParser XXXParser;

string::const_iterator tBegin = sTest.begin();

XXXParser.XXX(tBegin, sTest.end(), &plugin); 

// without the plugin parameter it would be written to cout

 

}

catch(CTT_ErrorExpected& xErr)

{

   cout << "expected: "

        << xErr.GetWhat()

        << " in "

        << xErr.GetProduction()

        << "\n";

}

catch(CTT_ErrorUnexpected& xErr)

{

   cout << "unexpected token in: "

        << xErr.GetProduction()

        << "\n";

}

catch(CTT_ParseError& xErr)

{

   cout << xErr.GetWhat()

        << " in "

        << xErr.GetProduction()

        << "; last token was: "

        << sTest.substr(xErr.GetLastPosition(), xErr.GetPosition() - xErr.GetLastPosition())

        << "\n";

}

catch(exception& xErr)

{

  cout << xErr.what();

}

catch (const OutOfMemoryException&)

{

  cout << ccpXercesOutOfMemory;

}

catch (const DOMException& e)

{

  cout << "xerces error code: " << e.code << endl;

  char *pMsg = XMLString::transcode(e.getMessage());

  cout << pMsg;

  XMLString::release(&pMsg);

}

catch (XMLException& e)

{

  char *pMsg = XMLString::transcode(e.getMessage());

  cout << pMsg;

  XMLString::release(&pMsg);

}

}

 



This page belongs to the TextTransformer Documentation

Home  Content  German