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 XML Man <xm...@bilbao.com> on 2001/06/18 13:32:06 UTC

getNodeValue().transcode()

Hi!

I'm trying to parse the value of a Node by using this piece
of code:

char *value;
value = attr.getNodeValue().transcode();
switch (value) {   
case "John":         
	printf("Your name is John\n");      
	break;                 
case "Tom": 
	printf("Hello, Tom!\n");      
	break;                 
}

But I get this error:
<<error C2450: switch expression of type 'char *' is illegal
        Integral expression required >>

Anybody could suggest an alternative to get the 'value'? 
_______________________________________________________________________
Tu correo gratuito en HispaVista - http://www.hispavista.com/altacorreo/

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


Re: getNodeValue().transcode()

Posted by Martin Kalen <ma...@todaysystems.com.au>.
----- Original Message -----
From: "Miroslaw Dobrzanski-Neumann" <mn...@mosaic-ag.com>

> In the previous mail I have redeclared "value" to
> std::string value(....transcode());

Sorry, my bad - I was all "C mode" after reading the previous replies
and did not see your string class declaration.

> there are rarely things that are not possible in C++

Overloading operator = and fooling this tired bloke, for one... :-)

/Martin

--
Martin Kalen
Software Engineer
TODAY Systems, Inc.
http://www.todaysystems.com.au/
Tel +61-3-9536 3900 - Fax +61-3-9536 3901


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


Re: getNodeValue().transcode()

Posted by Miroslaw Dobrzanski-Neumann <mn...@mosaic-ag.com>.
On Mon, Jun 18, 2001 at 09:53:59PM +1000, Martin Kalen wrote:
> ----- Original Message -----
> From: "Miroslaw Dobrzanski-Neumann" <mn...@mosaic-ag.com>
> > switch ()
> > expects an integral (bool, enum, int, ...) type not an array.
> 
> Correct...
> 
> > what about this:
> > if ("John" == value)
> 
> I would say "nay" to this considering all the side effects of pointer
> comparison. This is true if (and only if) the address of "value"
> equals the address where the compiler has put the const char* "John".

In the previous mail I have redeclared "value" to

std::string value(....transcode());
if ("John" == value)
is the same as
if (std::string("John") == value)
==> this is comparision of objects and not pointer
-- 
there are rarely things that are not possible in C++
	N. Josuttis
===================================
Miroslaw Dobrzanski-Neumann

MOSAIC SOFTWARE AG
Abteilung Basisentwicklung und Forschung
Tel +49-2225-882-291
Fax +49-2225-882-201
E-mail: mne@mosaic-ag.com


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


Re: getNodeValue().transcode()

Posted by Martin Kalen <ma...@todaysystems.com.au>.
----- Original Message -----
From: "Miroslaw Dobrzanski-Neumann" <mn...@mosaic-ag.com>
> switch ()
> expects an integral (bool, enum, int, ...) type not an array.

Correct...

> what about this:
> if ("John" == value)

I would say "nay" to this considering all the side effects of pointer
comparison. This is true if (and only if) the address of "value"
equals the address where the compiler has put the const char* "John".

Use str[n|case]cmp for this, but for a clean Xerces-C solution do as
Peter says and don't transcode at all (use the supplied
DOMString::equals).

Regards,
 Martin.

--
Martin Kalen
Software Engineer
TODAY Systems, Inc.
http://www.todaysystems.com.au/
Tel +61-3-9536 3900 - Fax +61-3-9536 3901


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


Re: getNodeValue().transcode()

Posted by Miroslaw Dobrzanski-Neumann <mn...@mosaic-ag.com>.
On Mon, Jun 18, 2001 at 02:36:04PM +0300, Peter A. Volchek wrote:
> > Hi!
> > 
> > I'm trying to parse the value of a Node by using this piece
> > of code:
> > 
> > char *value;
> > value = attr.getNodeValue().transcode();
> > switch (value) {   
> > case "John":         
> > printf("Your name is John\n");      
> > break;                 
> > case "Tom": 
> > printf("Hello, Tom!\n");      
> > break;                 
> > }
> > 
> > But I get this error:
> > <<error C2450: switch expression of type 'char *' is illegal
> >         Integral expression required >>
> > 
> > Anybody could suggest an alternative to get the 'value'? 
> 
> 
> char *value;
> value = attr.getNodeValue().transcode();
> printf("Your name is %s\n", value);      
> 
> :)

switch ()
expects an integral (bool, enum, int, ...) type not an array.

what about this:

std::string value(attr.getNodeValue().transcode());
if ("John" == value)
	printf("Your name is John\n");
else if ("Tom" == value)
	printf("Hello, Tom!\n");
else
	abort();
-- 
Miroslaw Dobrzanski-Neumann

MOSAIC SOFTWARE AG
Base Development and Research
Tel +49-2225-882-291
Fax +49-2225-882-201
E-mail: mne@mosaic-ag.com


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


Re: getNodeValue().transcode()

Posted by "Peter A. Volchek" <Pe...@ti.com.od.ua>.
> Hi!
> 
> I'm trying to parse the value of a Node by using this piece
> of code:
> 
> char *value;
> value = attr.getNodeValue().transcode();
> switch (value) {   
> case "John":         
> printf("Your name is John\n");      
> break;                 
> case "Tom": 
> printf("Hello, Tom!\n");      
> break;                 
> }
> 
> But I get this error:
> <<error C2450: switch expression of type 'char *' is illegal
>         Integral expression required >>
> 
> Anybody could suggest an alternative to get the 'value'? 


char *value;
value = attr.getNodeValue().transcode();
printf("Your name is %s\n", value);      

:)


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


Re: getNodeValue().transcode()

Posted by Stefan Berglund <st...@telia.se>.
Hi,

try:

char *value;
value = attr.getNodeValue().transcode();
if (strcmp(value, "John") == 0) {
    printf("Your name is John\n");
} else if (strcmp(value, "Tom") == 0) {
    printf("Hello, Tom!\n");
}
...
delete[] value;

Since char * cannot be used in switch() expressions, as it says in the
errormessage.
<<error C2450: switch expression of type 'char *' is illegal
        Integral expression required >>

Stefan

----- Original Message -----
From: <xm...@bilbao.com>
To: <xe...@xml.apache.org>
Sent: Monday, June 18, 2001 1:32 PM
Subject: getNodeValue().transcode()


Hi!

I'm trying to parse the value of a Node by using this piece
of code:

char *value;
value = attr.getNodeValue().transcode();
switch (value) {
case "John":
printf("Your name is John\n");
break;
case "Tom":
printf("Hello, Tom!\n");
break;
}

But I get this error:
<<error C2450: switch expression of type 'char *' is illegal
        Integral expression required >>

Anybody could suggest an alternative to get the 'value'?
_______________________________________________________________________
Tu correo gratuito en HispaVista - http://www.hispavista.com/altacorreo/

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


Re: getNodeValue().transcode()

Posted by "Peter A. Volchek" <Pe...@ti.com.od.ua>.
> Hi!
>
> I'm trying to parse the value of a Node by using this piece
> of code:
>
> char *value;
> value = attr.getNodeValue().transcode();
> switch (value) {
> case "John":
> printf("Your name is John\n");
> break;
> case "Tom":
> printf("Hello, Tom!\n");
> break;
> }
>
> But I get this error:
> <<error C2450: switch expression of type 'char *' is illegal
>         Integral expression required >>
>
> Anybody could suggest an alternative to get the 'value'?

Actually you do not need to transcode the attribute value to make a
comparison.
Use DOMString::equals method, smth like:

DOMString name = attr.getNodeValue();
if( name.equals( "John" )
{
    // Greet John
}
else if ( name.equals( "Tom" )
{
    // Say Hi to Tom
}
...



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