taprik
January 13, 2016, 9:41pm
#1
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 ?
arturo
January 13, 2016, 9:47pm
#2
it should work if you save the xml with utf8 encoding
taprik
January 14, 2016, 8:20am
#3
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
In SGML, HTML and XML documents, the logical constructs known as character data and attribute values consist of sequences of characters, in which each character can manifest directly (representing itself), or can be represented by a series of characters called a character reference, of which there are two types: a numeric character reference and a character entity reference. This article lists the character entity references that are valid in HTML and XML documents. A character entity reference r...
For some ones there is a trick but not for all of them.
my config.xml is as follows:
<test>ab&c</test>
i use the following code to read this xml:
string str1 = XML_.getValue("test","0");
but str1 is “abc” not “ab&c”. how can we read ‘&’ from xml?
I’ll try other way than xml …
taprik
January 14, 2016, 8:45am
#4
When I use the character substitution presented at
Le standard HTML demande de respecter le codage des caractères ASCII 7 bits, c'est-à-dire que les caractères accentués ne sont pas autorisés. Il faut pour cela utiliser un codage particulier. Pour coder un caractère accentué, il suffit de saisir...
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…
arturo
January 14, 2016, 9:26am
#5
you need to save the file itself as utf8 not only set the header.
taprik
January 15, 2016, 1:13pm
#6
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)
taprik
January 18, 2016, 3:05pm
#7
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