decimal symbol problem (using libxml2)

C

corley

Hello world,

I am having a problem with the decimal symbol. The result of writing a
floating-point-number

to an xml document (using libxml2 from xmlsoft.org) is
<number>10,1234</number>

The result I want is a dot as decimal symbol, like this
<number>10.1234</number>

If I adjust the county settings of my computer and say the decimal
symbol must be an dot it

works out fine, but this is not a very good solution because I dont
want to be dependent of

the system settings of a computer.

I have tried to use the setlocale function with setlocale(LC_ALL,
"English"). This didnt

seem to work.

Anybody has an clue?

Cheerz, David

-----------------------------
xmlTextWriterPtr writer = NULL;
xmlDocPtr doc = NULL;
char xmlFilename[100] = "uitvoer.xml";

writer = xmlNewTextWriterDoc(&doc, 0);
if (NULL != writer)
{
xmlTextWriterStartDocument(writer, NULL, "ISO-8859-1", NULL);
xmlTextWriterStartElement(writer, BAD_CAST "Main");
xmlTextWriterWriteFormatElement(writer, BAD_CAST "getal", "%f",
10.12345);
xmlTextWriterEndElement(writer);
xmlFreeTextWriter(writer);
xmlSaveFormatFile(xmlFilename, doc, 1);
xmlFreeDoc(doc);
}
 
F

Flash Gordon

corley said:
Hello world,

I am having a problem with the decimal symbol. The result of writing a
floating-point-number

to an xml document (using libxml2 from xmlsoft.org) is
<number>10,1234</number>

The result I want is a dot as decimal symbol, like this
<number>10.1234</number>

If I adjust the county settings of my computer and say the decimal
symbol must be an dot it

works out fine, but this is not a very good solution because I dont
want to be dependent of

the system settings of a computer.

I have tried to use the setlocale function with setlocale(LC_ALL,
"English"). This didnt

seem to work.

Anybody has an clue?

I don't think that "English" is a standard locate. "C", on the other
hand, is, and may well do what you want since it is the standard locale.
What other locales are available is dependant on your system so you
would have to ask in a group dedicated to your implementation, possibly
a Linux group. One of my linux boxes appears to have locales en_US and
en_GB, for example, but they are not part of the C standard.
Cheerz, David

<snip>

This looks like you are using the libxml2 library, which again is
non-standard and so off topic here (I use it myself, but I and all my
current customers will be set to either a British, USA or standard C
locale so I've not seen this problem). However, libxml2 has its own
mailing lists and it might be worth searching them.
http://xmlsoft.org/search.php?query=locale&scope=any&submit=Search+...
returns a lot of hits which would be worth investigating.
 
K

Keith Thompson

Flash Gordon said:
I don't think that "English" is a standard locate. "C", on the other
hand, is, and may well do what you want since it is the standard
locale. What other locales are available is dependant on your system
so you would have to ask in a group dedicated to your implementation,
possibly a Linux group. One of my linux boxes appears to have locales
en_US and en_GB, for example, but they are not part of the C standard.

But be careful about calling setlocale(LC_ALL, "C"). This (or the
equivalent) is done at program startup. If your program is operating
in a different locale, it must be because there was another call to
setlocale() with different arguments, possibly setlocale(LC_ALL, ""),
which "specifies the locale-specific native environment". If you set
the locale to "C", you could change the behavior of other parts of the
program that depend on a native or other locale.

It's possible to save and restore the locale; setlocale() with a null
pointer as its second argument returns a pointer to a string
representing the current locale. You can query and save the current
locale, do your stuff, then set it back.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,054
Latest member
LucyCarper

Latest Threads

Top