469,283 Members | 2,297 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,283 developers. It's quick & easy.

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));

Jul 17 '07 #1
7 2421

Meal <me*****@gmail.comwrote in
<11*********************@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
Jul 17 '07 #2
On 17 Jul., 06:35, Meal <meed...@gmail.comwrote:
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

Jul 17 '07 #3
On Jul 17, 5:41 am, spiff <sp...@gmx.atwrote:
On 17 Jul., 06:35, Meal <meed...@gmail.comwrote:
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.

Jul 17 '07 #4
On Jul 17, 5:41 am, spiff <sp...@gmx.atwrote:
On 17 Jul., 06:35, Meal <meed...@gmail.comwrote:
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.

Jul 17 '07 #5
On Jul 17, 5:20 am, Pavel Lepin <p.le...@ctncorp.comwrote:
Meal <meed...@gmail.comwrote 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/xe******.../msg11959.html

BTW, I'm having trouble to read new posts here. I have to wait several
hours to see a new post here.

Jul 17 '07 #6

Meal <me*****@gmail.comwrote in
<11**********************@g37g2000prf.googlegroups .com>:
On Jul 17, 5:20 am, Pavel Lepin <p.le...@ctncorp.com>
wrote:
>Meal <meed...@gmail.comwrote in
<1184646902.937613.34...@57g2000hsv.googlegroups. com>:
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
Jul 18 '07 #7
On 17 Jul., 16:17, Meal <meed...@gmail.comwrote:
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

Jul 18 '07 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Bekkali Hicham | last post: by
3 posts views Thread by Raphael Tagliani | last post: by
1 post views Thread by Simon Brooke | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.