I am processing an xml document and reading value from it. One of the value that am reading has / in it. This is how the value looks: M/S John Smith At 4. I was doing some testing on emulator and it was showing the correct value. Now i deployed my app to my Samsung Galaxy S2 device and the process is not reading the value correctly. It just shows M in the value field for that name.
I am thinking it could be because / is a special character. Is there something i can do to escape the special character in the value and read the whole name as it is?
P.S.: I am not an experienced Java Developer so this question may sound stupid to you but if you have the solution, please let me know.
When i am printing the value in console window, this is how it reads in the xmlDocument after parsing it: M/S John Smith At 4
This function reads the value:
public static String getCharacterDataFromElement(Element e) {
Node child = e.getFirstChild();
if (child instanceof CharacterData) {
CharacterData cd = (CharacterData) child;
return cd.getData();
}
return "";
}
In the adove function, cd.getdata() returns M
After some more debugging:
When i see the element in the watch window, for other names it has only one child. But for the element that contains / it got 3 children. It slices the stringbuffer bcz it sees / in there. I guess either i have to change the below function and ready all the child nodes or i have to use escape character in there before i pass it on.
This is what the new method now looks like:
As of now this is working. I dont know for how long but hopefully till i decide to do the right thing and iterate over child nodes and concatenate the string values.