Hi I have created xml where i need to pass file name and sent to server. It is working fine. But when the file name contains special character the name looks different in xml. similarly in reading same problem occurred. eg if file name is ♥♣◘• then i cant send the exact in xml also i cant read as it is from xml. How to resolve this type of issue. Whether i need to set any parameters in xml?
Thanks
Sunil Kumar Sahoo
Seems you have en ENCODING problem... Try out a few like UTF16 or UTF32... I know there are some issues in Android 'bout encoding stuff, you never really know what you get except if you FORCE it !
Try then using stuffs like :
String(byte[] data, String charsetName)
Converts the byte array to a string using the named charset.
with charsetname such as "UTF-8" or "UTF-16".
Related
I am getting some strings from json. My string contains special characters like "æ" from Næstved an many more like "ø" from køkken. But When I set Text these strings to ant textview, I get my strings printed in unusual way.
Example: For køkken I get kø ;kken.
I think I need to encode or decode my string somewhere but where I don,t know.
Please help.
Thanks in advance
The displayed version of your string represents an HTML encoded entity. You might want to verify that it is not coming in this way in your JSON data, but in any case, to decode it you can use the StringEscapeUtils.unescapeHtml4 method from Apache Commons Lang:
final String escaped = "køkken";
System.out.println(StringEscapeUtils.unescapeHtml4(escaped));
Output:
køkken
Did you check out the Latin Coding for your characters? I know the Ash character can be coded with æ and will show up æ in the browser.
Here is the a list of codes
Hope this helps!
I'm trying to store a fully qualified url, with also query params:
www.miosito.net?prova®=bis
but it's causing a problem because ® is similar to ® entity and android tell me that and html entity is not well written.
I need this because every locale uses a fully different set of url query param.
I tried with [[CDATA[.. ]] but this syntax disliked by xml parser.
The problem is not with &req but with & itself. For XML/HTML you would have to use & entity (or &), but for URLs you should rather URL-encode (see docs) strings, and in that case said & should be replaced with %26. So your final string should look like:
www.miosito.net?prova%26reg=bis
Store it like this:
<string name="my_url">"www.miosito.net?prova®=bis"</string>
Where & is the XML equivelant of the ampersand symbol &.
Percent encoding may do the trick: http://en.wikipedia.org/wiki/Percent-encoding
You'll basically have something like this: www.miosito.net?prova%26reg=bis
You can enclose your url in double quotes, something like :
<string name="my_url">"www.miosito.net?prova®=bis"</string>
This is a recommended way to enclose string resources in Android.
Update 1 : Have a look at the following link for more info :
http://developer.android.com/guide/topics/resources/string-resource.html#FormattingAndStyling
Update 2:
#WebnetMobile.com : Correct, indeed :)
'&' is being treated a special character by xml and enclosing in quotes doesn't work. I tried out
www.miosito.net?prova%26reg=bis
and it didn't work out either. I even tried enclosing it in quotes but still didn't work. Am I missing something ?
Meanwhile, the following does work :
<string name="my_url">www.miosito.net%1$sprova%2$sreg=bis</string>
and then in code :
Resources resources=getResources();
String url=String.format(resources.getString(R.string.my_url),"?","&") ;
The '%1$s' and '%2$s' are format specifiers, much like what is used in printf in C. '%1$s' is for strings, '%2$d' is for decimal numbers and so on.
I have a crash in an xml file. it occurs on a ë, in this case belgië (dutch for belgium).
I'm busy with searching for an answer but I just can't find a solution.
I'm using the sax parser under Android.
error: org.apache.harmony.xml.ExpatParser$ParseException: At line 2, column 204: not well-formed
xml source: http://biohorma.weatheronyoursite.com/villadm_hooikoortsverwachting_be.xml
Side note, i get the data via a stream, is the only option to put this stream to a temp value, replace the illegal character with a valid one and make a new stream of it or can you add something in the stream to do this?
It seems you should use the String (byte[] bytes, String enc) constructor, assuming what server sends you is encoded in UTF-8:
String properXml = new String(byteArrayIReceivedFromServer, "UTF-8");
The issue is not with the parser - it's acting correctly - but with whatever code is sending the XML. ë needs to be encoded and passed as ë. The same also must be done to other accented characters, ampersands and angle brackets.
You should replace special characters in the xml I think..
See a comprehensive list of chars here: http://www.w3schools.com/tags/ref_entities.asp
it says your umlaut e is like : Ë Ë Ë capital e, umlaut mark
Then also for a brief explanation if u feel like reading.
Hope it helps.
The server sends these headers:
Content-Type: text/xml
Content-Length: 124512
Since no charset is specified for content type, the normally correct assumption is US_ASCII. However, the XML payload seems to be encoded in ISO-8859-1
<?xml version="1.0" encoding="iso-8859-1"?>
and the 'ë' is encoded as 0xEB (235). It is very common for servers to encode text payload in ISO-8859-1, so this is something that one simply has to deal with.
My guess is that if you serve the parser with a byte stream directly, it will detect the encoding an act accordingly. If you use a character stream (not recommended), make sure to specify correct encoding.
I am extracting strings from KML file, if the string contains special character like !, #, #, ', " etc. its using codes like '
I am not able to extract entire string if it is like above, by calling getNodeValue(). It is terminating the string at special character.
<name>Continue onto Royal's Market</name>
If i extract the string i am getting only ""Continue onto Royal". I want entire string as
Continue onto Royal's Market.
How to achieve this ?? If anybody familiar with this please reply to this one.
Thanks
Your problem has nothing to do with KML but is general for XML parsning:
Don't use getNodeValue(), as there is no guarantee in DOM that text isn't actually split over several nodes.
Try using getTextContent() instead.
You might also have to replace entities, as in: node.getTextContent().replaceAll("'","'");
In general I wouldnt use DOM at all for extracting data.
I'd use the XmlPullParser as its simpler to work with - and parses faster.
For Android Platform:
I need to put Hebrew Character ₪ and some more like אורנג in string to check with the incoming data in java file. When I put this character It shows an error like "Some characters can not be mapped using "Cp1252" character encoding. Either change the encoding or remove the characters which are not supported by the "Cp1252" character encoding". These values are coming from SQLite database. Please see the attached snap. How can I solve this? Kindly give me some useful suggestions. Looking forward to hear from anybody who has a suggestion for me. Thanks.
Please open your eclipse.ini file from your eclipse folder with Note Pad and put the following permission into that.
-Dfile.encoding = UTF-8
Some more options as well:
For setting the encoding on a per WorkSpace basis, use Preferences->General->Workspace
To set the encoding on a per project basis open project properties and change to UTF-8
Hope this one help.
I think you'll need UTF-8 encoding for that.
These things are a little bit confusing. Reading this might clear some of the mist around encodings and character sets.
I think this may useful to you.
Keep this hebrew word in string.xml file. You can retrieve as
in String.xml
place hebrew word here
In java code:
String s=getString(R.string.hebrew_word);
Use this string as you want..