Element nodes have no value. You probably want to replace your call to tmp->getNodeValue () with tmp->getTextContent () (or scan the list of descendant text nodes yourself).
-----Original Message----- From: news [mailto:[EMAIL PROTECTED] On Behalf Of Vijay S. Bajwa Sent: Friday, January 05, 2007 10:31 AM To: [email protected] Subject: DOMParsing question Say I have a simple XML: <?xml version="1.0" encoding="UTF-8"?> <!--Sample XML file generated by XMLSpy v2007 (http://www.altova.com)--> <cnclMsg xsi:noNamespaceSchemaLocation="GTS-Oasys.xsd" xmlns:xsi="http://www.w3. org/2001/XMLSchema-instance"> <msgHdr> <dateTime>4294967295</dateTime> <institution>a</institution> <broker>a</broker> <reference>100001</reference> <version>4096</version> <brkrIntRef>aaaaaaaaaaaaaaaa</brkrIntRef> <instIntRef>aaaaaaaaaaaaaaaa</instIntRef> </msgHdr> <comment>aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</comment> </cnclMsg> I have parsed it and created a DOM tree. No I want to walk it and extract the data. I tried this general strategy. The trouble is that, for the msgHdr element node, I am able to get the "name" and then, I guess I will parse out this element. However, for the "comment" node, it does not give me any name, just something like "text" or something like that. Is there any way to get the name of a text node? The other alternative is to call getElementsByTagName() of which I have heard bad things. Appreciate your helpful comments! DOMElement* rootElmnt = doc->getDocumentElement() ; DOMElement* tmp; DBGOUT << "Root element: " << StrX(rootElmnt->getTagName()) << ENDL for (child = rootElmnt->getFirstChild(); child != 0; child=child->getNextSibling()) { // equivalent to typeof check and static cast if ( ! (tmp = dynamic_cast<DOMElement*>(child)) ) continue; name = StrX(tmp->getTagName()).localForm() ; DBGOUT << funcName << ": node name: " << name << ENDL if (strcmp(name, msgHdr) == 0) { get_msgHdr (tmp, &cncl->hdr, &cncl->trade_hdr); } else if (strcmp(name, comment) == 0) { val = StrX(tmp->getNodeValue ()).localForm(); int len = MIN (OAS_COMMENT_SIZE, strlen(val) ); strncpy (cncl->comment, val, len); } } Thanks! Vijay --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
