You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by "Awasthi, Anand" <An...@bmc.com> on 2001/06/08 23:30:59 UTC

node value length 0 ?? --strange

Hi,

I have following entity node defined: 


 <!ENTITY inputText "This is subtitution input text">



when i try to get the length of Node value ("This is subtitution input
text").
i use getNodeValue().length().



I get 0 why ?? 









-----Original Message-----
From: David_N_Bertoni@lotus.com [mailto:David_N_Bertoni@lotus.com]
Sent: Friday, June 08, 2001 4:07 PM
To: xerces-c-dev@xml.apache.org
Subject: RE: sample for down casting DOM_Node to DOM_Entity ??



You cannot use dynamic_cast with DOM_Node because it is not a polymorphic
type.  If your compiler lets you do this, you should throw it out and get a
new one.  The whole reason for using dynamic_cast is that you want run-time
type casting, not compile-time type casting, so if this doesn't compile,
it's probably not because the compiler figured out the actual type.

There are lots of examples of "downcasts" in the sample code.  If you like
old-style casts (which the Xerces code uses for portability), then use
those:

void
foo(DOM_Node  node)
{
    if (node.getNodeType() == DOM_Node::ENTITY_NODE)
    {
        DOM_Entity  ent = (DOM_Entity&)node;
    }
}

If you prefer new-style casts, which are safer, use those:

void
foo(DOM_Node  node)
{
    if (node.getNodeType() == DOM_Node::ENTITY_NODE)
    {
        DOM_Entity  ent = static_cast<const DOM_Entity&>(node);
    }
}

Dave



 

                    "Adams,

                    David"               To:
"'xerces-c-dev@xml.apache.org'" <xe...@xml.apache.org>    
                    <dadae@allsta        cc:     (bcc: David N
Bertoni/CAM/Lotus)                                 
                    te.com>              Subject:     RE: sample for down
casting DOM_Node to DOM_Entity ??       
 

                    06/08/2001

                    04:42 PM

                    Please

                    respond to

                    xerces-c-dev

 

 




No it is not safe. That is the old style of casting. With that style I
could
do something like this:
int x = 1;
DOM_Node n = (DOM_Node)x; // which you know is not right.

I suggest you use the following:
DOM_Entity domen = dynamic_cast<DOM_Entity>(node);
If it doesn't compile, it may be that the compiler is trying to tell you
that 'node' may NOT be a DOM_Entity type and you are doing an illegal cast.

Regarding the blank screen, in your example, if 'node' is not a DOM_Entity
type, you could be corrupting your screen memory.

> -----Original Message-----
> From:         Awasthi, Anand [SMTP:Anand_Awasthi@bmc.com]
> Sent:         Friday, June 08, 2001 3:33 PM
> To:           'xerces-c-dev@xml.apache.org'
> Subject:           RE: sample for down casting DOM_Node to DOM_Entity ??
>
> thanks guys...
>
> i tried
>
> DOM_Node node;
> DOM_Entity domen = (DOM_Entity &)(node);
>
> its compiles...but is this safe ??
>
> later on i want to print PublicId and SystemId associated with this
Entity
> node and
> i coded following:
>
> cout << "public id "  << ((DOM_Entity &)node).getPublicId().transcode()
<<
> endl;
> cout << "system id "  << ((DOM_Entity &)node).getSystemId().transcode()
<<
> endl;
>
> but I am getting blank screen . is the above code correct or is there any
> better
> implementation for obtaining PublicId and System Id value ?? pls suggest
> that.
>
> as a matter of fact when I use above DOMStrng.transcode() method to
obtain
>
> NOde Name ...i get Node Name. But when I try to obtain Node Value thru
> getNodeValue().transcode(),
> I get blank screen..whats wrong ??
>
>
>
> pls enlighten me
>
>
> thanks
> anand
>
>
>
>
>
>
> -----Original Message-----
> From: Adams, David [mailto:dadae@allstate.com]
> Sent: Friday, June 08, 2001 3:24 PM
> To: 'xerces-c-dev@xml.apache.org'
> Subject: RE: sample for down casting DOM_Node to DOM_Entity ??
>
>
> Curt is correct, in that I am assuming you know that the Node is an
> DOM_Entity type node and was passed around your code as a DOM_Node and
you
> simply want to get its derived type back. If you do not know what type it
> really is, you do have to check it. The VC++ macro "DYNAMIC_DOWNCAST" is
> another way to check if that works for you.
>
> > -----Original Message-----
> > From:       Adams, David [SMTP:dadae@allstate.com]
> > Sent:       Friday, June 08, 2001 3:16 PM
> > To:         'xerces-c-dev@xml.apache.org'
> > Subject:         RE: sample for down casting DOM_Node to DOM_Entity ??
> >
> > DOM_Node n = // some node;
> > DOM_Entity e = dynamic_cast<DOM_Entity>(n);
> >
> > I do not know what compiler you are using, but you will need to set the
> > /GR
> > switch on VC++ compilers. This is done by going to Project->settings,
> > select
> > the C/C++ tab, select the C++ Language category, and click on "Enable
> > Run-Time Type Information (RTTI)" to enable it.
> >
> > > -----Original Message-----
> > > From:          Awasthi, Anand [SMTP:Anand_Awasthi@bmc.com]
> > > Sent:          Friday, June 08, 2001 2:58 PM
> > > To:       'xerces-c-dev@xml.apache.org'
> > > Subject:       sample for down casting DOM_Node to DOM_Entity ??
> > >
> > > Hi,
> > >
> > > could someone pls provide sample code for down casting DOM_Node to
> > > DOM_Entity ??
> > >
> > > thanks
> > > Anand
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
> > > For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
> > For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-c-dev-help@xml.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org






---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org