Return-Path: Delivered-To: apmail-xml-xerces-c-dev-archive@xml.apache.org Received: (qmail 83307 invoked by uid 500); 4 Feb 2003 18:02:42 -0000 Mailing-List: contact xerces-c-dev-help@xml.apache.org; run by ezmlm Precedence: bulk Reply-To: xerces-c-dev@xml.apache.org list-help: list-unsubscribe: list-post: Delivered-To: mailing list xerces-c-dev@xml.apache.org Received: (qmail 83183 invoked from network); 4 Feb 2003 18:02:41 -0000 Message-ID: <3E4000E0.9040103@boris-glawe.de> Date: Tue, 04 Feb 2003 19:05:20 +0100 From: Boris Glawe User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.3a) Gecko/20030203 X-Accept-Language: de-de, en-us, en MIME-Version: 1.0 To: xerces-c-dev@xml.apache.org Subject: Re: getNodeValue() crashes References: In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N David N Bertoni/Cambridge/IBM wrote: > > 1. XMLString::transcode() returns a pointer to dynamic memory that you > must delete. If you don't, it's a memory leak: > > char* str = XMLString::transcode(...); > > delete [] str; > > I am assigning this value to a string... do I have to delete this string, too ?? > 2. Element nodes have no value, so getValue() is probably returning a > null pointer. The "value" of an Element is contained in its Text > children, so you must iterate through the children to get the value. > According to the API getNodeValue() returns a const XMLCh*.. what does the returnvalue contain, if not the text of the node 'element' ?? Even if it returns null, why does it crash ?? this null value should be assigned to string....!?? Do you have any hints, which classes/methods/mechanisms to use, when iterating through the Text Children ?? thanks Boris >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 >#include > >#include >#include >#include >#include > >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 ######################################## > > > > > > hallo > > > > > > > > > >-- >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: xerces-c-dev-unsubscribe@xml.apache.org >For additional commands, e-mail: xerces-c-dev-help@xml.apache.org > > > > >--------------------------------------------------------------------- >To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org >For additional commands, e-mail: xerces-c-dev-help@xml.apache.org > > > > > -- 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: xerces-c-dev-unsubscribe@xml.apache.org For additional commands, e-mail: xerces-c-dev-help@xml.apache.org