What's wrong with following codes? (xerces)

M

Meal

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

Pavel Lepin

Meal said:
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.
 
M

Meal

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.
 
M

Meal

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.
 
M

Meal

<[email protected]>:







Well, you're casting from Base* to Derived*. Ewww...
*shudder*


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.

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/[email protected]/msg11959.html

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

Pavel Lepin

Meal said:
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.



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.
 
S

spiff

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top