Reputation: 1043
I am getting xml in a object back from a soap service.
<data><name>Test</name><name>Test</name><name>Test</name></data>
I need to convert that into an array so i can input it into a list
String[] accounts = result(this is my object);
setListAdapter(new ArrayAdapter<String>(this, R.layout.listaccounts, accounts));
How can i do this.
Upvotes: 0
Views: 498
Reputation: 2812
If the XML structure is so simple then regular expression will solve it for you.
private static final Pattern pattern = Pattern.compile("<name>([^<]+)</name>");
.....
Matcher m = pattern.compile(xmlString);
List<String> retList = new ArrayList<String>();
while(m.find()) {
retList.add(m.group(1));
}
return retList;
It could be parsed even faster with String.indexOf();
Oh yeah: boatloads of people will tell you to use XML parser. It's complete overkill for simple XML. As long as it's not nested and you're not interested in attributes etc... simpler methods will do just fine.
Upvotes: 1
Reputation: 5183
you have to parse the XML response and then fill the String array. For XML parsing, you can use the SAXParser.
Hope this helps!
Upvotes: 0