M
mearvk
A good bit of it is commented out so pay attention. I get a seg fault
(just says Segmentation Fault) when trying to run this with the line
below uncommented. I'm a java programmer so excuse the clumniness of
the code; it's still very early in development.
This line seems to be the culprit, but I'm not sure why:
document->getElementsByTagName(targetNodes); std::cout<<"7";
Help appreciated,
Max
[START SOURCE]
#include <string.h>
#include <iostream>
#include <xercesc/util/PlatformUtils.hpp>
#include <xercesc/parsers/XercesDOMParser.hpp>
#include <xercesc/dom/DOM.hpp>
#include <xercesc/dom/DOMDocument.hpp>
#include <xercesc/dom/DOMDocumentType.hpp>
#include <xercesc/dom/DOMElement.hpp>
#include <xercesc/dom/DOMImplementation.hpp>
#include <xercesc/dom/DOMImplementationLS.hpp>
#include <xercesc/dom/DOMNodeIterator.hpp>
#include <xercesc/dom/DOMNodeList.hpp>
#include <xercesc/dom/DOMText.hpp>
#include "DDAS_XML_Parser.h"
XERCES_CPP_NAMESPACE_USE
int main(int argc, char* argv[])
{
try
{
//XMLPlatformUtils::Initialize();
}
catch (const XMLException& toCatch)
{
// Do your failure processing here
//return 1;
}
// Do your actual work with Xerces-C++ here.
std::string fileURL="results.xml";
int* defNums=getDefinitionNumbers(fileURL.c_str());
//Terminate DDAS_XML_Parser
//XMLPlatformUtils::Terminate();
// Other terminations and cleanup.
return 0;
}
void echo(const char* e)
{
std::cout<<e;
}
int* getDefinitionNumbers(const char* file_URL)
{
try
{
XMLPlatformUtils::Initialize();
}
catch (const XMLException& toCatch)
{
char* message =
XMLString::transcode(toCatch.getMessage());
std::cerr<<"ERROR:"<<message<<"."<<std::endl;
XMLString::release(&message);
}
std::cout<<"1";
XercesDOMParser* parser = new XercesDOMParser();
parser->setValidationScheme(XercesDOMParser::Val_Auto);
parser->setDoNamespaces(false);
parser->setDoSchema(false);
parser->setLoadExternalDTD(false);
std::cout<<"2";
//DOMDocument* document;
//DOMElement * rootNode;
//DOMNodeList* nodeList;
XMLCh* targetNodes = XMLString::transcode("dataRow");
XMLCh* targetAttrs = XMLString::transcode("defNumber");
try
{
XMLPlatformUtils::Initialize();
}
catch (const XMLException& toCatch)
{
char* message =
XMLString::transcode(toCatch.getMessage());
std::cerr<<"ERROR:"<<message<<"."<<std::endl;
XMLString::release(&message);
}
std::cout<<"3";
try
{
parser->parse(file_URL);
std::cout<<"4";
DOMDocument* document=parser-
std::cout<<"7";
}
catch(const XMLException& toCatch)
{
char* message =
XMLString::transcode(toCatch.getMessage());
std::cerr<<"ERROR:"<<message<<"."<<std::endl;
XMLString::release(&message);
}
//CLEAN UP
//delete parser;
XMLPlatformUtils::Terminate();
return NULL;
}
/*
*
* g++ -c DDAS_XML_Parser.C
* g++ -L/usr/src/xerces-c-src_2_8_0/lib -lxerces-c
DDAS_XML_Parser.o -o test
*
*
*/
[STOP SOURCE]
(just says Segmentation Fault) when trying to run this with the line
below uncommented. I'm a java programmer so excuse the clumniness of
the code; it's still very early in development.
This line seems to be the culprit, but I'm not sure why:
document->getElementsByTagName(targetNodes); std::cout<<"7";
Help appreciated,
Max
[START SOURCE]
#include <string.h>
#include <iostream>
#include <xercesc/util/PlatformUtils.hpp>
#include <xercesc/parsers/XercesDOMParser.hpp>
#include <xercesc/dom/DOM.hpp>
#include <xercesc/dom/DOMDocument.hpp>
#include <xercesc/dom/DOMDocumentType.hpp>
#include <xercesc/dom/DOMElement.hpp>
#include <xercesc/dom/DOMImplementation.hpp>
#include <xercesc/dom/DOMImplementationLS.hpp>
#include <xercesc/dom/DOMNodeIterator.hpp>
#include <xercesc/dom/DOMNodeList.hpp>
#include <xercesc/dom/DOMText.hpp>
#include "DDAS_XML_Parser.h"
XERCES_CPP_NAMESPACE_USE
int main(int argc, char* argv[])
{
try
{
//XMLPlatformUtils::Initialize();
}
catch (const XMLException& toCatch)
{
// Do your failure processing here
//return 1;
}
// Do your actual work with Xerces-C++ here.
std::string fileURL="results.xml";
int* defNums=getDefinitionNumbers(fileURL.c_str());
//Terminate DDAS_XML_Parser
//XMLPlatformUtils::Terminate();
// Other terminations and cleanup.
return 0;
}
void echo(const char* e)
{
std::cout<<e;
}
int* getDefinitionNumbers(const char* file_URL)
{
try
{
XMLPlatformUtils::Initialize();
}
catch (const XMLException& toCatch)
{
char* message =
XMLString::transcode(toCatch.getMessage());
std::cerr<<"ERROR:"<<message<<"."<<std::endl;
XMLString::release(&message);
}
std::cout<<"1";
XercesDOMParser* parser = new XercesDOMParser();
parser->setValidationScheme(XercesDOMParser::Val_Auto);
parser->setDoNamespaces(false);
parser->setDoSchema(false);
parser->setLoadExternalDTD(false);
std::cout<<"2";
//DOMDocument* document;
//DOMElement * rootNode;
//DOMNodeList* nodeList;
XMLCh* targetNodes = XMLString::transcode("dataRow");
XMLCh* targetAttrs = XMLString::transcode("defNumber");
try
{
XMLPlatformUtils::Initialize();
}
catch (const XMLException& toCatch)
{
char* message =
XMLString::transcode(toCatch.getMessage());
std::cerr<<"ERROR:"<<message<<"."<<std::endl;
XMLString::release(&message);
}
std::cout<<"3";
try
{
parser->parse(file_URL);
std::cout<<"4";
DOMDocument* document=parser-
DOMElement* rootNode=document-getDocument(); std::cout<<"5";
//document->getElementsByTagName(targetNodes);getDocumentElement(); std::cout<<"6";
std::cout<<"7";
}
catch(const XMLException& toCatch)
{
char* message =
XMLString::transcode(toCatch.getMessage());
std::cerr<<"ERROR:"<<message<<"."<<std::endl;
XMLString::release(&message);
}
//CLEAN UP
//delete parser;
XMLPlatformUtils::Terminate();
return NULL;
}
/*
*
* g++ -c DDAS_XML_Parser.C
* g++ -L/usr/src/xerces-c-src_2_8_0/lib -lxerces-c
DDAS_XML_Parser.o -o test
*
*
*/
[STOP SOURCE]