What's wrong with following codes? (xerces)

Discussion in 'XML' started by Meal, Jul 17, 2007.

  1. Meal

    Meal Guest

    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));
     
    Meal, Jul 17, 2007
    #1
    1. Advertising

  2. Meal

    Pavel Lepin Guest

    Meal <> wrote in
    <>:
    > 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
     
    Pavel Lepin, Jul 17, 2007
    #2
    1. Advertising

  3. Meal

    spiff Guest

    On 17 Jul., 06:35, Meal <> 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
     
    spiff, Jul 17, 2007
    #3
  4. Meal

    Meal Guest

    On Jul 17, 5:41 am, spiff <> wrote:
    > On 17 Jul., 06:35, Meal <> 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, Jul 17, 2007
    #4
  5. Meal

    Meal Guest

    On Jul 17, 5:41 am, spiff <> wrote:
    > On 17 Jul., 06:35, Meal <> 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, Jul 17, 2007
    #5
  6. Meal

    Meal Guest

    On Jul 17, 5:20 am, Pavel Lepin <> wrote:
    > Meal <> wrote in
    > <>:
    >
    >
    >
    > > 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//msg11959.html

    BTW, I'm having trouble to read new posts here. I have to wait several
    hours to see a new post here.
     
    Meal, Jul 17, 2007
    #6
  7. Meal

    Pavel Lepin Guest

    Meal <> wrote in
    <>:
    > On Jul 17, 5:20 am, Pavel Lepin <>
    > wrote:
    >> Meal <> wrote in
    >> <>:
    >> > 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.


    I didn't say *the* DOMXPathEvalua... someone in the rear end. -- Garrison Keillor
     
    Pavel Lepin, Jul 18, 2007
    #7
  8. Meal

    spiff Guest

    On 17 Jul., 16:17, Meal <> 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
     
    spiff, Jul 18, 2007
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Greg  --
    Replies:
    4
    Views:
    2,172
  2. mike
    Replies:
    3
    Views:
    397
    Virgil Green
    Jul 11, 2005
  3. cvissy
    Replies:
    0
    Views:
    609
    cvissy
    Nov 16, 2004
  4. Replies:
    2
    Views:
    2,846
    Malcolm
    Aug 20, 2005
  5. Allen
    Replies:
    1
    Views:
    659
    Mark Rae [MVP]
    Dec 3, 2007
Loading...

Share This Page