We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi
This is my first post in here. I have a simple problem with getting Scandinavian characters back from a xml. Æ, Ø and Å all come out wrong from this code.
String url = "http://suggestqueries.google.com/complete/search?output=toolbar&hl=dk&q=ærø";
void setup() {
XML xml = loadXML(url);
XML[] children = xml.getChildren("CompleteSuggestion");
for (int i = 0; i < children.length; i++) {
XML suggestion = children[i].getChild("suggestion");
println(suggestion);
}
}
If you visit the url http://suggestqueries.google.com/complete/search?output=toolbar&hl=dk&q=ærø you see, that the characters Æ, Ø Å all work fine on the url itself.
Help is much appreciated.
Regards Andreas from Denmark
Answers
Indeed when directly loading from the URL, the encoding fails.
However, after saving & loading it locally it strangely worked.
Perhaps the original isn't UTF-8 and somehow became so after saving it locally? :-??
hmm, strange...
I need to load it from the XML however, my sketch is going to be interactive (the example is just provided to boil down the problem)...
byte[]
.byte[]
, passing along the Charset decoder for it.https://Processing.org/reference/loadBytes_.html
http://docs.Oracle.com/javase/8/docs/api/java/lang/String.html#String-byte:A-java.nio.charset.Charset-
http://docs.Oracle.com/javase/8/docs/api/java/nio/charset/Charset.html
https://Processing.org/reference/parseXML_.html
Thanks! I think it is a bit above my skill-level... How do I find out which encode is being used?
http://docs.Oracle.com/javase/8/docs/api/java/nio/charset/Charset.html
http://forum.Processing.org/two/discussion/11682/how-to-specify-charset-when-converting-byte-to-string
Wow! Thanks a lot GoToLoop :-)
I really appreciate it, hope I myself can help others the way you just helped me!