The documentation seems to imply that you'll always get a node list back from getElementsByTagName(), but it might be worth checking whether your nodes variable is null before dereferencing it. That's basic defensive programming.
Assuming nodes points to a valid node list, you don't need to check the list's length. Just fetch nodes->item(0) and check to see whether the result is null before dereferencing it. Note that your snippet has a memory leak. XMLString::transcode() returns a pointer to allocated memory; you need to release that memory. -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Tuesday, September 02, 2008 7:15 AM To: [email protected] Subject: Problem with not existing Node Hello I have the following Problem: xerces shut down my programm when it wants to output an non existing node, here an exmple. I want to read out the text of the elements. <xml> <element_a >test</element_a> <element_b />test</element_b> </xml> The source code: DOMNodeList* nodes = root->getElementsByTagName(XMLString:transcode("elementa")); cout << nodes->item(0)->getTextContent() << endl; This code makes no Problem while i ask for elemts which are in the xmlfile below, but if i ask for element_c which is not in the xml file the code before exit my programm by reaching the code line nodes->item(0)->getTextContent(). I have also tried to get out if the pointer is empty or there is no nodes with nodes->getlength() , but also here xerces is closing down my programm without an error message. If someone had an idea where the problem ist or how i can solve the problem please write it to me Thanks David P.S I hope you understand my problem
