type conversion - XE2 XML Attribute can't convert to double -


i have xml node attributes this:

<pad name="e" x="2.5" y="7" drill="1.3"/> 

when assign attributes["x"] double result 25, not 2.5 without complaints or errors.

to correct conversion first have assign attribute string, replace decimal '.' decimal ',' , convert string double. attribute["x"] can't convert doesn't anything! (bug?!?)

here code faulty conversion:

double x = xmlnode->attributes["x"]; 

this gives faulty x of 25 instead of 2.5 , here work around:

string sd = xmlnode->attributes["x"]; if (sd.pos(".")) sd[sd.pos(".")] = ','; double x = sd.todouble(); 

this gives correct value in x (2.5)

there must more simple way this!

// thanks

xml attributes arbitrary string values if not using xsd coherce data, such ide's xml data binding wizard. attributes[] property returns olevariant, in case going contain system::string in it. when system::string converted double using olevariant's double conversion operator or string::todouble() method, conversion uses global sysutils::decimalseparator variable, initialized using pc's locale settings, using , character decimal separator instead of . character. xml has no way of knowing locale setting.

since using modern version of c++builder, can use overloaded version of strtofloat() function lets pass in tformatsettings record input. can specific . tformatsettings::decimalseparator use conversion, eg:

tformatsettings fmt = tformatsettings::create(); fmt.decimalseparator = '.'; double x = strtofloat(xmlnode->attributes["x"], fmt);  

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -