I am a beginner, so hope you're not bored with my problem...
I am using gcc3.2 on Redhat 8.0... I compiled the xerces-c library myself...
The program crashes, as soon, as I try to call the getNodeValue() method
of a DOMNode...
The used xml file (test.xml) is at the bottom....
According to the API all types are correct... What am I doing wrong ??
Read the comments in the prgram
for further information.
It compiles without any warnings (though -Wall), and without errors...
Maybe, I've something done wrong, when compiling the xerces-c library
(I used './runConfigure -p linux -c gcc -x g++' and then 'gmake' as
recommended in the docs)??
//#####################################
#include <iostream>
#include <string>
#include <xercesc/dom/DOM.hpp>
#include <xercesc/parsers/XercesDOMParser.hpp>
#include <xercesc/util/PlatformUtils.hpp>
#include <xercesc/sax/HandlerBase.hpp>
using namespace std;
int main(int argc, char* argv[]) {
try {
XMLPlatformUtils::Initialize();
}
catch(const XMLException& toCatch){
cout << "Exception message is:" <<
XMLString::transcode(toCatch.getMessage())
<< endl;
return -1;
}
XercesDOMParser* parser = new XercesDOMParser();
ErrorHandler* err = (ErrorHandler*) new HandlerBase();
parser->setErrorHandler(err);
char* xmlFile = "/home/boris/test.xml";
try {
parser->parse(xmlFile);
}
catch (XMLException& toCatch){
cout << "Exception is: " << XMLString::transcode (toCatch.getMessage())
<< endl;
return -1;
}
catch (DOMException& toCatch){
cout << "Exception is: " << XMLString::transcode (toCatch.msg) << endl;
return -1;
}
catch (...) {
cout << "unexpected Exception: " << endl;
return -1;
}
DOMDocument* doc = parser->getDocument();
DOMNodeList* list =
doc->getElementsByTagName(XMLString::transcode("element"));
string text = "";
DOMNode* node = list->item(0);
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
/*Problem starts here... program crashes when calling getNodeValue()
* tried also char* as type for text. Shouldn't it assign the value
* 'hallo' to the string text ??
*/
if (node){
text = XMLString::transcode(node->getNodeValue());
//program crashes here....!!!!!!!!!!!!!!!
}
else {
// node ist not null, thus this is not executed..
cout << "Failure: maybe node is empty" << endl;
}
cout << text << endl;
//this does also not work
//cout << XMLString::transcode(list->item(0)->getNodeValue()) << endl;
//this again works, when commenting out the code above.. and shows
//the name 'element' and that there is one element in the nodelist...
cout << XMLString::transcode(list->item(0)->getNodeName()) << endl;
cout << list->getLength() << endl;
cout << "Exiting normally" << endl;
return 0;
}
########## test.xml ########################################
<?xml version="1.0"?>
<test xmlns="http://www.boris-glawe.de/">
<element>
hallo
</element>
</test>
--
Stop TCPA and Palladium !!!
watch these sites if you want to learn more:
english:
http://www.cl.cam.ac.uk/~rja14/tcpa-faq.html
german:
http://moon.hipjoint.de/tcpa-palladium-faq-de.html
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
- Re: getNodeValue() crashes Boris Glawe
- Re: getNodeValue() crashes David N Bertoni/Cambridge/IBM
- Re: getNodeValue() crashes Boris Glawe
- Re: getNodeValue() crashes David N Bertoni/Cambridge/IBM
- RE: getNodeValue() crashes Steve Smith
