![]() |
What's wrong with following codes? (xerces)
The last line of the following codes makes the program crash.
I cannot debug into the codes. It looks that I cannot use the dynamic_cast, but why? The cout shows that the node is DOM element node. I think it's possible to cast it from DOMNode* to DOMElement*. I need the cast to use method getElementsByTagName() which DOMNode doesn't have. XMLCh* tagTuple = XMLString::transcode("tuple"); DOMNodeList * listTuple = doc->getElementsByTagName(tagTuple); XMLString::release(&tagTuple); if(listTuple->getLength()==0) { return; } //For the first tuple cout<<listTuple->item(0)->getNodeType()<<endl; DOMElement* tuple = dynamic_cast<DOMElement*>(listTuple->item(0)); |
Re: What's wrong with following codes? (xerces)
Meal <meedeex@gmail.com> wrote in <1184646902.937613.34770@57g2000hsv.googlegroups.c om>: > The cout shows that the node is DOM element node. I think > it's possible to cast it from DOMNode* to DOMElement*. > I need the cast to use method getElementsByTagName() which > DOMNode doesn't have. > > XMLCh* tagTuple = XMLString::transcode("tuple"); > DOMNodeList * listTuple = > doc->getElementsByTagName(tagTuple); > XMLString::release(&tagTuple); > > if(listTuple->getLength()==0) > { > return; > } > //For the first tuple > cout<<listTuple->item(0)->getNodeType()<<endl; > DOMElement* tuple = > dynamic_cast<DOMElement*>(listTuple->item(0)); > > The last line of the following codes makes the program > crash. Well, you're casting from Base* to Derived*. Ewww... *shudder* > I cannot debug into the codes. It looks that I > cannot use the dynamic_cast, but why? Googling seems to indicate reinterpret_cast<> is used among those who lost hope to deal with this... peculiarity. I hope you're aware that's equivalent to telling your compiler 'Stfu, stupid, I know better.' I think using a DOMXPathEvaluator instead of getElementsByTagName() member function would be a much better solution, though. -- ....the pleasure of obedience is pretty thin compared with the pleasure of hearing a rotten tomato hit someone in the rear end. -- Garrison Keillor |
Re: What's wrong with following codes? (xerces)
On 17 Jul., 06:35, Meal <meed...@gmail.com> wrote:
> DOMElement* tuple = dynamic_cast<DOMElement*>(listTuple->item(0)); Hi meal! I guess you don't have RTTI (check for "run time type information") enabled in your compiler settings. Without this dynamic_cast throws an exception and crashes if not handled. Regards spiff http://www.spycomponents.com |
Re: What's wrong with following codes? (xerces)
On Jul 17, 5:41 am, spiff <sp...@gmx.at> wrote:
> On 17 Jul., 06:35, Meal <meed...@gmail.com> wrote: > > > DOMElement* tuple = dynamic_cast<DOMElement*>(listTuple->item(0)); > > Hi meal! > > I guess you don't have RTTI (check for "run time type information") > enabled in your compiler settings. Without this dynamic_cast throws an > exception and crashes if not handled. > > Regards spiffhttp://www.spycomponents.com Hi, thanks for your reply. I had thought about this, and in VS2003 I enabled it with "Enable Run- Time Type Info" setting to Yes (/GR), but still have the same error. |
Re: What's wrong with following codes? (xerces)
On Jul 17, 5:41 am, spiff <sp...@gmx.at> wrote:
> On 17 Jul., 06:35, Meal <meed...@gmail.com> wrote: > > > DOMElement* tuple = dynamic_cast<DOMElement*>(listTuple->item(0)); > > Hi meal! > > I guess you don't have RTTI (check for "run time type information") > enabled in your compiler settings. Without this dynamic_cast throws an > exception and crashes if not handled. > > Regards spiffhttp://www.spycomponents.com Hi, thanks all you guys. It turns out to be that xerces lib itself is not compiled with RTTI. |
Re: What's wrong with following codes? (xerces)
On Jul 17, 5:20 am, Pavel Lepin <p.le...@ctncorp.com> wrote:
> Meal <meed...@gmail.com> wrote in > <1184646902.937613.34...@57g2000hsv.googlegroups.c om>: > > > > > The cout shows that the node is DOM element node. I think > > it's possible to cast it from DOMNode* to DOMElement*. > > I need the cast to use method getElementsByTagName() which > > DOMNode doesn't have. > > > XMLCh* tagTuple = XMLString::transcode("tuple"); > > DOMNodeList * listTuple = > > doc->getElementsByTagName(tagTuple); > > XMLString::release(&tagTuple); > > > if(listTuple->getLength()==0) > > { > > return; > > } > > //For the first tuple > > cout<<listTuple->item(0)->getNodeType()<<endl; > > DOMElement* tuple = > > dynamic_cast<DOMElement*>(listTuple->item(0)); > > > The last line of the following codes makes the program > > crash. > > Well, you're casting from Base* to Derived*. Ewww... > *shudder* > > > I cannot debug into the codes. It looks that I > > cannot use the dynamic_cast, but why? > > Googling seems to indicate reinterpret_cast<> is used among > those who lost hope to deal with this... peculiarity. I > hope you're aware that's equivalent to telling your > compiler 'Stfu, stupid, I know better.' > > I think using a DOMXPathEvaluator instead of > getElementsByTagName() member function would be a much > better solution, though. > > -- > ...the pleasure of obedience is pretty thin compared with > the pleasure of hearing a rotten tomato hit someone in the > rear end. -- Garrison Keillor Hi, thanks for your suggestions. I'm trying to use XPATH, but it turns out that it's not fully supported in Xerces. I always get exeption 9. Please have a look at the following link. http://www.mail-archive.com/xerces-c.../msg11959.html BTW, I'm having trouble to read new posts here. I have to wait several hours to see a new post here. |
Re: What's wrong with following codes? (xerces)
Meal <meedeex@gmail.com> wrote in <1184684909.583144.316860@g37g2000prf.googlegroups .com>: > On Jul 17, 5:20 am, Pavel Lepin <p.le...@ctncorp.com> > wrote: >> Meal <meed...@gmail.com> wrote in >> <1184646902.937613.34...@57g2000hsv.googlegroups.c om>: >> > The cout shows that the node is DOM element node. I >> > think it's possible to cast it from DOMNode* to >> > DOMElement*. I need the cast to use method >> > getElementsByTagName() which DOMNode doesn't have. >> >> I think using a DOMXPathEvaluator instead of >> getElementsByTagName() member function would be a much >> better solution, though. > > I'm trying to use XPATH, but it turns out that it's not > fully supported in Xerces. > I always get exeption 9. > Please have a look at the following link. [url] I didn't say *the* DOMXPathEvaluator, which is just an interface, I said *a* DOMXPathEvaluator. I believe the URL you posted actually provides a pointer in the right direction. For that matter, you might want to take a look at Xalan as well. -- ....the pleasure of obedience is pretty thin compared with the pleasure of hearing a rotten tomato hit someone in the rear end. -- Garrison Keillor |
Re: What's wrong with following codes? (xerces)
On 17 Jul., 16:17, Meal <meed...@gmail.com> wrote:
> Hi, thanks all you guys. > It turns out to be that xerces lib itself is not compiled with RTTI. The usual pitfall on using dynamic_cast as it is just not enough to turn it on where you use it... Regards |
| All times are GMT. The time now is 01:03 PM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.