Re: [xml] xmlChar to int conversion



There isn't some xmlCharToInt type of function already in  libxml?

On Tue, 2003-04-08 at 16:25, Stefan Seefeld wrote:
Nick Torenvliet wrote:
I guess at the same time I should ask how to get an int back to an
xmlChar.

On Tue, 2003-03-11 at 13:59, Nick Torenvliet wrote:

Hi, I have a property of a tag and I need to convert it into an integer.

I am really unfamiliar with UTF8 so I am not sure how to take something
from an xmlChar * to an integer.  How can I succesfully complete the
following?

int i;
i = xmlGetProp(cur,"val");


what do you mean by 'convert' ? Is the character actually a number in 
the range [0,9] ? If that's what you want, you can do it like this:

int i;
xmlChar *attr = xmlGetProp(cur, "val");
if (*attr >= '0' && *attr <= '9') i = (int)*attr;

If you expect an ascii letter and want to map that to an int, you
should test whether *attr really represents an ascii char, and then
cast it. Otherwise the conversion won't work, since arbitrary utf8
characters may be larger than an int can hold.

Oh, and if the attribute contains a *string* such as "42", you really
have to parse it, one character at a time, using the above technique
(i.e. to exclude non-ascii chars).

Regards,
              Stefan

_______________________________________________
xml mailing list, project page  http://xmlsoft.org/
xml gnome org
http://mail.gnome.org/mailman/listinfo/xml
-- 
Nick Torenvliet B.A.,B.Eng.
FieldStone Solutions
www.fieldstonesolutions.com




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]