Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How can i covert XML string to Java Array in android

 
Reece Baron
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys so i am trying to create a login right now the login is ok but what i am trying to do is convert this

to a java array so i can display the data upon login is there anyone who can help with this i also have this thread http://www.coderanch.com/t/617746/Android/Mobile/login-XML-array

 
Atul Itankar
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

In simple way we can do like this for converting string to array

public static int[] strngToArr(String str)
{
int length = str.length();
int[] array = new int[length];
for (int i = 0; i < length; i++)
{
array[i] = Integer.parseInt(str.substring(i,i+1));
}
return array;
}

But in Android we have a separate file for string objects, where all string objects are stored.
For that you need to parse xml objects one by one then convert it into array.

I will try and get back to you.

Thanks
Atul Itankar

InfoCepts | www.infocepts.com
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Splitting strings and converting numbers is definitely not the way to do it: it will be brittle and a ton of work. You should use the built in mechanisms for XML parsing in Android. This link from the Android Developer's Network is a good place to get started: http://developer.android.com/training/basics/network-ops/xml.html
 
Reece Baron
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Steve Luke wrote:Splitting strings and converting numbers is definitely not the way to do it: it will be brittle and a ton of work. You should use the built in mechanisms for XML parsing in Android. This link from the Android Developer's Network is a good place to get started: http://developer.android.com/training/basics/network-ops/xml.html


and thats for XML format i have ?
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Reece Baron wrote:
Steve Luke wrote:Splitting strings and converting numbers is definitely not the way to do it: it will be brittle and a ton of work. You should use the built in mechanisms for XML parsing in Android. This link from the Android Developer's Network is a good place to get started: http://developer.android.com/training/basics/network-ops/xml.html


and thats for XML format i have ?


The point of a library is that it works in a general way. It will work for your XML because it doesn't make any assumptions on the structure, other than being well-formed. It leaves you to determine what the structure of the XML means, while the library just parses out the data from the structure and gives it to you as it gets it.
 
Reece Baron
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Steve Luke wrote:
Reece Baron wrote:
Steve Luke wrote:Splitting strings and converting numbers is definitely not the way to do it: it will be brittle and a ton of work. You should use the built in mechanisms for XML parsing in Android. This link from the Android Developer's Network is a good place to get started: http://developer.android.com/training/basics/network-ops/xml.html


and thats for XML format i have ?


The point of a library is that it works in a general way. It will work for your XML because it doesn't make any assumptions on the structure, other than being well-formed. It leaves you to determine what the structure of the XML means, while the library just parses out the data from the structure and gives it to you as it gets it.


Ok thanks mate now i just have to get the login to work with it once i have it all working
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The login and XML parsing should be two completely different things, they are not related. Even if you have to log in to download the XML, then you have three distinct steps (log in, download, parse). I would suggest not intermingling the three.
 
Reece Baron
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Steve Luke wrote:The login and XML parsing should be two completely different things, they are not related. Even if you have to log in to download the XML, then you have three distinct steps (log in, download, parse). I would suggest not intermingling the three.


I have never done this before but i can see it will be hard to do
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic