Android :: XML Parsing With Encoding Using Android

May 25, 2010

I am facing some problems on xml parsing with android. The problem is that the xml from the server comes in "ISO-8859-1" set with setEncoding (I get <?xml version="1.0" encoding="ISO-8859-1"?>) format and the android device seems that its ignoring that encoding. For example this is part of the original xml that comes from the server:

<Result Filename="Pautas para la Present RUP Iteraciones de Construcci.ppt">
<Path>C:Documents and SettingszashaelMy DocumentsPFCRUPPautas para la Presentaci RUP Iteraciones de Construcci.ppt</Path>
<Hostname>computer_1</Hostname>
<IP>192.168.0.5:27960</IP>
<ModDate>01-ene-1601 2:06:34</ModDate>
<Size>33.280 bytes</Size></Result>

And this is what I get on the phone before parsing the xml:
</Result>
<Result Filename="Pautas para la Presentaci RUP Fase Inicio.ppt">
<Path>C:Documents and SettingszashaelMy DocumentsPFCRUPPautas para la Presentaci RUP Fase Inicio.ppt</Path>
<Hostname>computer_1</Hostname>
<IP>192.168.0.5:27960</IP>
<ModDate>01-ene-1601 1:32:06</ModDate>
<Size>26.624 bytes</Size>
</Result>

As you can see there is a problem with the word "presentaci". This is the part of code where I recieve the file, and then send it to the parser:

do { auxMessage = ois.readObject();
if (auxMessage instanceof ComConstants) {
receivedMessage = (ComConstants) auxMessage;
Log.d("Client", "Client has Search Results");
//Charset charset = Charset.forName("ISO-8859-1");
//CharsetDecoder decoder = charset.newDecoder();
//CharsetEncoder encoder = charset.newEncoder();
String test; test = new String(
receivedMessage.fileContent, 0, receivedMessage.okBytes);
if (finalMessage == null) { finalMessage = test;
} else { finalMessage += test;
}
/*try { // Convert a string to ISO-LATIN-1 bytes in a ByteBuffer
// The new ByteBuffer is ready to be read.
ByteBuffer bbuf = encoder.encode(CharBuffer.wrap(finalMessage));
// Convert ISO-LATIN-1 bytes in a ByteBuffer to a character ByteBuffer and then to a string.
// The new ByteBuffer is ready to be read.
CharBuffer cbuf = decoder.decode(bbuf);
String s = cbuf.toString(); finalMessage = s;
} catch (CharacterCodingException e) { }
}*/ } else { Log.d("Client", "Unexpected message " + auxMessage.getClass().getName());
break; } } while (!receivedMessage.lastMessage);
//test encoding
//String s = finalMessage;
//finalMessage = new String(s.getBytes("ISO-8859-1"));
System.out.println("antes de parsear" + finalMessage);
SaxParser sap = new SaxParser(finalMessage);

And this is my parser code:
package citic.android.remoteir;
import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.Iterator;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.DefaultHandler;
public class SaxParser extends DefaultHandler{
@SuppressWarnings("unchecked")
ArrayList myResults;
private String tempVal;
private SearchResult tempResults;
@SuppressWarnings("unchecked")
public SaxParser(String xmlString){
myResults = new ArrayList();
parseDocument(xmlString);
/* In order to test */ printData();
} @SuppressWarnings("unchecked")
public ArrayList getResults(){ return myResults;
} private void parseDocument(String xmlString) {
try { SAXParserFactory spf = SAXParserFactory.newInstance();
spf.setFeature("http://xml.org/sax/features/namespaces",false);
spf.setFeature("http://xml.org/sax/features/namespace-prefixes",true);
SAXParser sp = spf.newSAXParser();
XMLReader xmlReader = sp.getXMLReader();
xmlReader.setContentHandler(this);
StringReader sr = new StringReader(xmlString);
InputSource is = new InputSource(sr);
is.setEncoding("ISO-8859-1");
xmlReader.parse(is);
}catch(SAXException se) { se.printStackTrace();
}catch(ParserConfigurationException pce) {
pce.printStackTrace();
}catch (IOException ie) { ie.printStackTrace();
} }
@SuppressWarnings("unchecked") private void printData(){
System.out.println("No of Results '" + myResults.size() + "'.");
Iterator it = myResults.iterator();
while(it.hasNext()) { System.out.println(((SearchResult) it.next()).toString());
//System.out.println(it.next().toString());
} }
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { tempVal = "";
if(qName.equalsIgnoreCase("Result")) { tempResults = new SearchResult();
tempResults.setName(attributes.getValue("Filename"));
} }
public void characters(char[] ch, int start, int length) throws SAXException {
tempVal = new String(ch,start,length);
} @SuppressWarnings("unchecked")
public void endElement(String uri, String localName, String qName) throws SAXException {
if(qName.equalsIgnoreCase("Result")) { myResults.add(tempResults);
}else if (qName.equalsIgnoreCase("Hostname")) { tempResults.setHostname(tempVal);
}else if (qName.equalsIgnoreCase("IP")) { tempResults.setIpad(tempVal);
}else if (qName.equalsIgnoreCase("Path")) { tempResults.setPath(tempVal);
/*}else if (qName.equalsIgnoreCase("Author")) { tempResults.setHostname(tempVal);
}else if (qName.equalsIgnoreCase("File")) { tempResults.setIpad(tempVal);
*/}else if (qName.equalsIgnoreCase("ModDate")) { tempResults.setModDate(tempVal);
}else if (qName.equalsIgnoreCase("Size")) { tempResults.setSize((tempVal));
} } }
I dont know what to do. I tried setting the string I create after recieving the xml bytes to ISO encoding, but the only thing I got was a "square" instead of " ".

Android :: XML Parsing With Encoding using Android


Android :: Web View Encoding? Why?

May 28, 2010

I have started to work with the WebView component of Android Platform, but the API to load data to the component is confusing me, because it includes a parameter with a encoding. In both methods: public void loadData (String data, String mimeType, String encoding); public void loadDataWithBaseURL (String baseUrl, String data, String mimeType, String encoding, String historyUrl); you have to specify an encoding. In both cases, the API documentation says that is is the encodign of the data (data parameter). Well, as know, if you provide data as a String object, the String is internally stored in UTF-16 (unicode). To get a String object from a external source, you need to specify the external source encoding to convert it to UTF-16 and get the String internal representation (String(byte[] data, String encoding)). So, at this moment, when you have an String instance, everything from the original source has been converted to UTF-16. So, why do you need to specify an encoding if you are providing the data as a String object?

I don't know the internal implementation of WebKit, but let's suppose that, WebKit has a method, to render a source, providing as content an InputStream and a default encoding. Well, as I know, when you process a HTML page, you use the default encoding to read the HTML characters, and if you find a <meta> tag specifing a different encoding, from that moment, you have to use the new encoding to decode the characters of the HTML page. But what happens if you supply a HTML page that contains this <meta> tag: <meta HTTP-EQUIV="content-type" CONTENT="text/html; charset=ISO-8859-1"/> using one of the methods specified at the top of this post, how are you going to read ISO-8859-1 encoding from a String that it is in UTF-16 encoding? if the WebKit filtering this <meta> tags, and doesn't taking in account the encoding specified in this tag? Well, all of this is very confusing for me, because I don't understand why the API includes this encoding parameter. I also don't know if the <meta> encoding tags are filtered when the source is provided as a String? Can anyone solve my doubts?

View 2 Replies View Related

Android :: How To Check Encoding In Java

Nov 19, 2010

I am facing a problem about encoding.

For example,
I have a message in xml format encoding is "UTF-8".

CODE:.........

Now, this message are supporting multiple language.
Traditional Chinese (big5), Simple Chinese (gb), English (utf-8)

And it will only change the encoding in specific fields.
For example (Traditional Chinese),

CODE:..........

Only "蘋果" and "橙" are using big5, "<product_name>" and "</product_name>" stills in use utf-8.
<price>1.3</price> and <price>1.2</price> are using utf-8.

How do I know which word is using different encoding?

View 3 Replies View Related

Android :: Defining Data Encoding Of SMS Messages

Aug 24, 2010

I'm working on an application using the SMS apis for android. The receiving end is an embedded unit that only supports 7-bit encoded SMS and the string I'm sending consists only of symbols from this particular alphabet which makes you think that Android is going to send it encoded as 7 bit. But that is not the case.Therefore I'm searching for a way to specify what encoding to use. See below for what my code looks like today. The method gsm7BitPackedToString turns a byte-array to a 7-bit string, i.e. the string only consists of 7-bit compatible characters and is copied from the internal android api. Code...

View 2 Replies View Related

Android :: Default Encoding Of Operating System?

Feb 5, 2010

What is the default encoding of android system?

View 1 Replies View Related

Android :: What Xml Encoding Work For Non European Languages

Mar 15, 2010

Assume I want to write an xml resource file with a a non-europian language, say japanese, thai or chinese-What encodings can I use and what do I have to to to both the xml header and the Writer to makes these work - Also is there an easy way to map a Locale into acceptable encodings

View 4 Replies View Related

Android : Way To Update SDK / Support Encoding Qcelp

Apr 8, 2009

I've added one new feature to Opencore & Framework to let them support encoding qcelp. But I found that Eclipse cannot figure out this new feature, e.g.

recorder.setOutputFormat(MediaRecorder.OutputFormat.RAW_QCELP);recorder.setAudioEncoder(MediaRecorder.AudioEncoder.QCELP);

Eclipse now does not think RAW_QCELP & QCELP as legal symbols. So, what should I do to update the SDK to pass though this issue? Overwrite its system.img, boot.img or some *.jar packages?

View 3 Replies View Related

Android :: Chunked Encoding - GZIP Input Stream

Mar 3, 2010

I found a problem with GZIP input stream when wrapping InputStream from HttpURLConnection. When the server response with Transfer- Encoding=chunked, Content-Encoding=gzip and Connection=Keep-Alive. The second post always return -1. After digging into the source code, I found the place that could be a bug: InflaterInputStream.java (line 190 to 192) if (inf.needsInput()) { fill(); } Because InflaterInputStream doesn't need more input, it doesn't try to read the end of chunked encoding (0x)(30 0a 0d) that cause the second post to return with -1 every time.

View 3 Replies View Related

Android :: Http Proxy And Chunked Encoding With Emulator

Mar 24, 2009

I am having a specific problem that is preventing me using the android SDK from work. We are using a MS Proxy here that all internet traffic has to go through. The problem seems to be when the emulator is trying to access a site that uses 'Transfer-Encoding: chunked' If I attempt to download www.nds.com (no chunked encoding) into the browser, it works fine. However if I try to go to www.google.com (uses chunked encoding), the browser fails with the message: can't determine content length, and client wants to keep connection opened My feeling (and I'm no expert in this area) is that the underlying code managing the communication through the proxy is not dealing with the null terminator on the chunk encoded response when the connection to the proxy is being kept open? Does anyone have any experience in this area? Is the source to the emulator available so I can try and understand what is going on here?

View 8 Replies View Related

Android :: Convert InputStream To String With Encoding Given In Stream Data?

May 20, 2010

My input is a InputStream which contains an XML document. Encoding used in XML is unknown and it is defined in the first line of XML document.
From this InputStream, I want to have all document in a String.

To do this, I use a BufferedInputStream to mark the beginning of the file and start reading first line. I read this first line to get encoding and then I use an InputStreamReader to generate a String with the correct encoding.

It seems that it is not the best way to achieve this goal because it produces an OutOfMemory error.

Any idea, how to do it ? code...

View 1 Replies View Related

Android :: File's Chinese Characters Can't Be Displayed / Droid Support ANSI Encoding These?

Aug 26, 2009

I have two text file, both of them contains Chinese characters, one text file is saved using ANSI encoding, but this file's Chinese characters can not be displayed by htmlviewer on the phone. The Chinese characters in another txt file saved using unicode can be displayed ok by htmlviewer. Do you have any suggestions on this, does Chinese characters using ANSI encoding supported?

View 3 Replies View Related

HTC Incredible :: Best Video Encoding Settings

Aug 9, 2010

I'm trying to rip some DVDs from my collection and get them on my phone for a trip that I will be taking. I just tried to convert one 480x880, 30fps, Constant Bitrate @ 100%, MP4, x264. IDK what went wrong but it wouldn't play from my phone but played fine on my Mac. Does anyone have any suggestions?

View 4 Replies View Related

General :: Mail Characters Encoding?

Jun 3, 2012

I don't know why but some emails I sent aren't showing properly. If I write something like: "hey, what have you planned for tomorrow"?

It's delivered like this:

=?UTF-8?B?5pS25Yiw5LqM5pak5Zub55uS6ZOB6KeC6Z+z?=
MIME-Version: 1.0
Content-Type: text/html; charset="utf-8"
Content-Transfer-Encoding: base64[code]...

At first I thought it was because of some ROM so I made a clean install of Gingerbread.This didn't fix it so I updated to ICS. Not even changing my written language from Chinese to English worked.

View 7 Replies View Related

Samsung Captivate :: DD 5.1 - Video Files Encoding

Aug 10, 2010

I'm able to get AC3 5.1 @ 640kbs to work with my 720p mkv files but the playback skips about every 5 seconds. Other then that It looks and sounds amazing! I've tried encoded to 5.1 FLAC and AAC but it doesn't play at all. Are there any encoding experts out there?

View 1 Replies View Related

General :: LG P970 Optimus - Incoming SMS Encoding

Jul 3, 2012

I have LG P970 Optimus black. I know this problem is about a lot of devices and a lot of regions. We are using latin alphabet with some special characters. like "ı, ş, �, ğ, �.." when someone sends me a text message with this characters,

It is normally shown in cm7 and its based roms.
It is normally shown in lg roms which are released for turkey
but it is shown like one space in different lg roms.

For fixing it, what can i do. Is it about message apk? or about some libs?

View 1 Replies View Related

Android :: Way To Get Rid Of "warning : Unmappable Character For Encoding Ascii"

Apr 12, 2010

I'm compiling using android tools without eclipse.

I compile launching "ant debug" from command line.

I have found many many instructions around the web about how to remove with annoying warning, but I haven't been able to make any of them work.

I've tried -D option, I've tried randomly tweaking build.* files, I've tried exporting an environment variable... nothing.

I guess some of these methods just don't work, and some others would work but I've been doing them incorrectly. Anything is possible and I can't stand it any more: any advice on how to do it?

View 3 Replies View Related

Sprint HTC Hero :: Text Encoding Mean / Default Is Latin?

Apr 23, 2010

It's in the browser settings I have mine on Latin Japanese and unicode are also some other options. I think default is Latin?

View 3 Replies View Related

General :: Samsung Galaxy S - Force SMS Encoding From Unicode To ISO

Aug 16, 2010

I'm from Portugal and here we have some accentuated letters like "à á é ç ã õ".

When the system language is set to English and we insert one of these letters the SMS limit falls down from 160 charachters to 70 because it changes the encoding of the SMS .

What I would like to know is if it's possible to come with an hack to force the system to encode the SMS in a particular way so these kind of letters don't cut us 90 characters off the message.

Actually this is a problem in a lot of countries. Spain, France, Portugal, Italy, Brazil, Mexico, Argentina and the list goes on... Any country that speeks a latin language really.

PS: I own a Samsung Galaxy S at the moment

View 9 Replies View Related

Motorola Droid X :: Video Recording / Options For Encoding (MPEG4 Or H.263)

Sep 23, 2010

I have two questions regarding video recording on the Droid X.

1. What options are there for encoding? On my HTC Hero I can encode in MPEG4 or H.263. What about the Droid X?

2. My friend sent me a video from her Droid X, but I can't hear anything as far as audio in a normal setting. The only way I can pick up anything she's saying is if I max out the Media volume and hold the speaker directly up to my ear. Is there something she's doing wrong when she's recording the video? This has happened twice now.

View 1 Replies View Related

Android :: Parsing XML From Net Using SAX

Apr 8, 2009

I really have a problem: When I want to parse this XML file:

XML file:
<marketexport> <createtime_timestamp>1236801648</createtime_timestamp> <createtime_date>11.03.09 - 21:00</createtime_date> <ressources> <ressource> <name>Energie</name> <price>14</price> <number>11967033</number> </ressource> </ressources> <race> <race_name>Nova Federation</race_name> <military_units> <unit> <name>NoF Marine</name> <price>1200</price> <number>845</number> </unit> </military_units> <spy_units> <unit> <name>Thief</name> <price>0</price> <number>0</number> </unit> <unit> <unit> <name>Agent</name> <price>0</price> <number>0</number> </unit> </spy_units> </race> </marketexport>

ExampleHandler:

public void startElement(String namespaceURI, String localName,
String qName, Attributes atts) throws SAXException {
if (localName.equals("marktexport")) { this.in_marktexport = true;
} if (localName.equals("ressources")) { this.in_ressources = true;
} if (localName.equals("ressource")) { this.in_ressource = true;
} if (localName.equals("race")) { this.in_race = true;
} if (localName.equals("race_name")) { this.in_race_name = true;
} if (localName.equals("military_units")) { this.in_military_units = true;
} if (localName.equals("unit")) { this.in_unit = true;
} if (localName.equals("name")) { this.in_name = true;
} if (localName.equals("price")) { this.in_price = true;
} if (localName.equals("number")) { this.in_number = true;
} }
public void endElement(String namespaceURI, String localName, String qName)
throws SAXException { if (localName.equals("marktexport")) { this.in_marktexport = false;
} if (localName.equals("ressources")) { this.in_ressources = false;
} if (localName.equals("ressource")) { this.in_ressource = false;
} if (localName.equals("name")) { this.in_name = false;
} if (localName.equals("price")) { this.in_price = false;
} if (localName.equals("number")) { this.in_number = false;
} if (localName.equals("race")) { this.in_race = false;
} if (localName.equals("race_name")) { this.in_race_name = false;
} if (localName.equals("military_units")) { this.in_military_units = false;
} if (localName.equals("unit")) { this.in_unit = false;
} } public void characters(char ch[], int start, int length) { if(this.in_race_name){
myParsedExampleDataSet.setrace(new String(ch, start, length));
} if(this.in_name){ myParsedExampleDataSet.setname(new String(ch, start, length));
} if(this.in_price){ myParsedExampleDataSet.setprice(new String(ch, start, length));
} if(this.in_number){ myParsedExampleDataSet.setnumber(new String(ch, start, length));
} }
ParsedExampleDataSet:
public void setprice(String price){ this.price = price;
} public void setname(String name) { this.name = name;
} public void setnumber(String number) { this.number = number;
} public void setrace(String race) { this.race = race;
} //Getter public String getnumber() { return number;
} public String getprice() { return price;
} public String getname() { return name;
} public String getrace() { return race;
} //.toString() public String toString() {
result = getrace()+"
Name: "+getname()+"
Preis: "+getprice() +"
Number: "+getnumber();
return result;
}
I Only get:
Nova Federation Name: Agent Preis: 0 Anzahl: 0
So I want to get: Nova Federation Name: NoF Marine Preis: 1200 Number: 845

View 2 Replies View Related

XML Parsing In Android

Aug 5, 2012

i have to get the data information from mysql database and display it in android emulator successfully. This is my code:

Code:
public class CustomizedListView extends Activity {
// All static variables
static final String URL = "http://192.168.1.168/pro/orderdetails.xml";
// XML node keys
static final String KEY_SONG = "Order"; // parent node
static final String KEY_ID = "orderid";
static final String KEY_TITLE = "orderid";
static final String KEY_ARTIST = "payment_method";
static final String KEY_DURATION = "total";
[code]...

Here i have to successfully displayed on android emulator. but i wish to display on first page ordered and payment_method only.then it is move to next page means have to display total for that particular id. I wish output is :

13(orderid) Phone ordering(payment_method)
14(orderid) check (payment_method)
15(orderid) Phone ordering(payment_method)
if i clicked 13 means that particular order total only displayed on next activity.

View 1 Replies View Related

Android :: Inner Elements During The Xml Parsing

Aug 23, 2010

I could not get any inner elements during the xml parsing. looks like parser see only outer tag A. Could you show me error?

CODE:.......................

View 4 Replies View Related

Android :: Parsing Xml File With DOM

Oct 2, 2010

I have a xml file and i am parsing it with DOM.

CODE:........

My code is giving bellow:

CODE:..................

Now my problem is this i want all url of all media:content tag,, but getting only 1st url of every media:content tag.

View 2 Replies View Related

Android :: Parsing Xml Error

Aug 19, 2010

When i'm using this code, it says the parsing xml error.

This code is from K9mail (string.xml file @ 256 line)

CODE:....................

View 2 Replies View Related

Android :: XML Parsing In Java

Jul 11, 2010

The API I need to work with does not support xpath, which is a bit of a headache! The xml I want to parse is as a String. My questions: Is there a Java equivalent of "simplexml_load_string", where it makes the string into an xml document for parsing? Which is better for parsing, SAX or DOM? I need to get a couple of values out of the XML and the structure isn't that deep. [3 levels]

View 2 Replies View Related

Android :: IOException On SAX Parsing

Apr 25, 2009

I'm trying to parse an XML file from res/raw or assets/ using the javax SAX parser. When the file is too large (~ 1MB), the parse(...) method throws an IOException without further information, such as message or inner exception. When I reduce file size to e. g. 600 kB, it's working again.

View 2 Replies View Related

Android :: Parsing XMl Using Xpath?

Aug 20, 2010

I want to parse an xml file using xpath in android, any idea how to do that?

View 2 Replies View Related

Android :: Best XML Parsing Library?

Oct 13, 2010

I have to parse some complex xml files inside my Android application. Is there any good library for doing that like there is TouchXMl for iPhone?

View 2 Replies View Related

Android :: How To Do XML Parsing In Droid

Nov 18, 2010

I am new to android and XML. so, i would like to know what is XML parsing and how and where we can use it in android application development.
I would also like to know the syntax to be used for this purpose.

View 2 Replies View Related

Android : XML Parsing Is Slow

Dec 5, 2009

I like to parse a XML file in android. It is taking too much time to parse a xml in android. what is the reason?.. It is taking more than 5 minutes also to parse a file. The same thing will continue in phone?...

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved