Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   XML (http://www.velocityreviews.com/forums/f32-xml.html)
-   -   What's wrong with following codes? (xerces) (http://www.velocityreviews.com/forums/t522484-whats-wrong-with-following-codes-xerces.html)

Meal 07-17-2007 04:35 AM

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


Pavel Lepin 07-17-2007 09:20 AM

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

spiff 07-17-2007 09:41 AM

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


Meal 07-17-2007 01:42 PM

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.


Meal 07-17-2007 02:17 PM

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.


Meal 07-17-2007 03:08 PM

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.


Pavel Lepin 07-18-2007 05:55 AM

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

spiff 07-18-2007 09:49 PM

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.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57