0

How do I access the encoding for an xml-file using TBXML?

To clarify: I would like to acsess the top row in an xml-file and there get the value of encoding by using TBXML.

?xml version="1.0" encoding="utf-8"?

Alecktos
  • 77
  • 1
  • 6

1 Answers1

0

You can't, it's not part of the xml document.

Why do you want to know the encoding?

deanWombourne
  • 38,189
  • 13
  • 98
  • 110
  • Because some files are using ISO-8859-1 encoding while others are using utf-8 – Alecktos Jul 04 '11 at 16:23
  • But why do you need to care - surely the xml decoder will deal with that for you? – deanWombourne Jul 04 '11 at 21:01
  • Because when I have a file that is using ISO-8859-1 and try to get the text for an element (using TBXML) that have letters like å, ä, ö I just get an empty string. If I change the encoding in the TBXML:class I can get it to work but then I get problems when I have an xml-file that is using UTF-8. – Alecktos Jul 05 '11 at 07:12
  • Hmm, Tricky. Assuming that you can't change the encoding of the xml yourself beforehand, take a look at this question : http://stackoverflow.com/questions/5268661/how-to-detect-text-file-encoding-in-objective-c - this should let you know the encoding. The other way is to read in the file in ASCII and parse it for 'encoding=...' but that's a nasty hack! – deanWombourne Jul 05 '11 at 11:38
  • Managed to get to work by looking at the other question and using stringWithContentsOfFile:usedEncoding:error: Thanks! – Alecktos Jul 05 '11 at 15:43