Loading XML values with special character (à, é, ù, ....)

Hy there,

I’m trying to load values from xml file with some accents.
I’m using this code :

string title, enTete;
if (XML.load("settings.xml")) {
	XML.setTo("account");
	title = XML.getValue("title", "default title text");
	enTete = XML.getValue("entete", "default enTete text");
	cout << "values loaded" << endl;
}

cout << title << "   " << enTete << endl;

where XML is a ofXml

with this XML file settings.xml.zip (667 Bytes)

I’ve tried it with windows, mac, OF 0.8.4, OF 0.9. None of this configurations are working.
Is it a limitation of OF or of the XML standard ?
Do you know a way to load string with special characters in OF ?

it should work if you save the xml with utf8 encoding

Actually when I change the first line of my xml file to

<?xml version="1.0" encoding="UTF-8"?>

the parsing of the xml file give me an error

 [ error ] ofXml: parse error: Invalid token in line 3 column 20

when it reads the first é

I’ve already read that xml can not parse any character


For some ones there is a trick but not for all of them.

I’ll try other way than xml …

When I use the character substitution presented at

it works on Mac with

<?xml version="1.0" encoding="ISO-8859-1"?>

or

<?xml version="1.0" encoding="UTF-8"?>

in the first line.

The same thing is not working for windows…

you need to save the file itself as utf8 not only set the header.

Thanks Arturo,

With a file encoded in utf8 it’s working on osx with the code of my first post.
On windows I’ve got nothing with ofXml :

  • Same code, same file, but nothing is read.

With ofxXmlSettings on Windows, the getValue method return a string but with a
|-®
in place of every special character

I’m using this tips to get a correct xml file
http://symbolcodes.tlt.psu.edu/web/tips/xml.html

Her is the code with the ofxXmlSettings class

if (XML.load("settings.xml")) {
	XML.pushTag("account");
	title = XML.getValue("title", "default title text");
	enTete = XML.getValue("entete", "default enTete text");
	cout << "values loaded" << endl;
}
cout << title << "   "  <<enTete<< endl;

here is the xml file settings.zip (240 Bytes)

Actually windows console does not support utf-8.

This is where my mess start !

Thanks Arturo for your help.

And the method on my previous post works :wink: