java - Weird characters after processing a xml file in android -
i making andorid applicaiton loads data xml file. problem xml file not processed correctly , not able serialize it, because of that. think problem related encoding of file.
how made xml file? eclipse have clicked on new-> file -> , created blank xml, i've filled needed information.
here how xml looks in editor:
<?xml version="1.0" encoding="utf-8"?> <data> <categories> <category value="inbox"/> <category value="private"/> <category value="work"/> <category value="business"/> </categories> <todos> <todo> <id>1</id> <text>explore app!</text> </todo> <todo> <id>2</id> <text>add more todos!</text> <date>2013-05-09 12:21:55 cet</date> </todo> </todos> </data>
i getting xml file res/xml , load file in input stream. after converting file string using string constructor.
here java code:
inputstream = getresources().openrawresource(r.xml.startingdata); bytearrayoutputstream bos = new bytearrayoutputstream(); int next = is.read(); while (next > -1) { bos.write(next); next = is.read(); } bos.flush(); byte[] result = bos.tobytearray(); xmldata = new string(result,"utf-8");
after step, show new xmldata toast, check how looks. receive part of data, plus weird characters. doing wrong? thank in advance! attaching image testing device, in order show weird toast result:
you need set encoding of xml utf 8. can right clicking on file , set file encoding drop down.
Comments
Post a Comment