I have a file called products.xml
in res/xml/products.xml with this XML data:
<?xml version="1.0" encoding="UTF-8"?>
<products>
<product>
<productname>Jeans</productname>
<productcolor>red</productcolor>
<productquantity>5</productquantity>
</product>
<product>
<productname>Tshirt</productname>
<productcolor>blue</productcolor>
<productquantity>3</productquantity>
</product>
<product>
<productname>shorts</productname>
<productcolor>green</productcolor>
<productquantity>4</productquantity>
</product>
</products>
and my main goal is to parse it using XMLPullParser. But I'm getting a weird output when I try to open the file. Here is the code I am using:
BufferedReader in = null;
try {
in = new BufferedReader(new InputStreamReader(appContext
.getResources().openRawResource(R.xml.products), "UTF-8"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (NotFoundException e) {
e.printStackTrace();
}
StringBuilder s = new StringBuilder();
String line;
while ((line = in.readLine()) != null) {
s.append(line);
}
System.out.println("String: " + s);
and I'm getting a strange output with a bunch of these characters:
�������������������������������������������������������������������
What am I doing wrong? Thanks
No comments:
Post a Comment