tags:

views:

50

answers:

1

Respected All, I have to read XML file, for that I use SAXParser and DefaultHandler using method characters(char[] ch, int start, int length) but it gives output with some extra characters such as [] in place of '#13'. someone told me that if I read that string in UTF-8 format then it will remove that all the extra characters. Is it true that I have to read it in UTF-8 format if yes then how I can read it. Thank You (Vikram Kadam)

A: 

I use this to parse with the SAXparser :

URL url = new URL(urlToParse);
SAXParserFactory spf = SAXParserFactory.newInstance();
// here we get our SAX parser
SAXParser sp = spf.newSAXParser();
// we fuse it to a XML reader
XMLReader xr = sp.getXMLReader();
DefaultHandler handlerContact = new DefaultHandler();
// we give it a handler to manage the various events
xr.setContentHandler(handlerContact);
// and finally we open the stream to the url
InputStream oS = url.openStream();
// and parse it
xr.parse(new InputSource(new InputStreamReader(oS, Charset.forName("utf-8"))));
// to retrieve the list of contacts created by the handler
result = handlerContact.getEntries();
// don't forget to close the resource
oS.close();

I never had any trouble as long as the initial file you are parsing is properly encoded in UTF-8. Check if it is, because sometimes, when you use default configuration of your computer, default is not UTF-8 but ANSI or ISO-8859-1

Sephy
Thank You Sephy It gives me Utf-8 format string but there are some html tags such as <b> or <b> and displaying at various places. Is ther any way to remove these tags at once? if yes please help me.
Vikram
Yep, for this kind of tags you have to pass your string to Html.fromHtml method. It will return your tags with the proper formatting. Then you can put it in a WebView for instance.Don't forget to check/vote the answer if it solved your problem.
Sephy
Thank You Sephy. It Works fine and displaying output without any html tags.I was searching it for more than three days, but this function works fine.
Vikram
Hi Sephy, This is vikram. can u help me to play video files from raw folder using class MediaPlayer.
Vikram
I have use MediaPlayer mp = MediaPlayer.create(VideoPlayer.this,R.raw.dobeernotdrugs);
Vikram
mp.start(). but it not showing any thing on screen... Thank you.
Vikram
hi Vikram, you should simply ask a new question, not over comment this one with another topic ;)
Sephy