简体   繁体   中英

Android - Getting data from XML file on the web

I need to get data from an XML file in Android. On the iPhone environment, my code is:

NSURL *thisURL = [[NSURL alloc] initWithString:@"http://www.xxx.com/file.xml"];
NSArray *myArray = [[NSArray alloc] initWithContentsOfURL:providerURL];

myArray is now an array of dictionary items initialized with contents from file.xml.

Is there any way to do this in Android? Can someone point me to doc or sample code?

I'm new to the Android environment and just need some direction.

Thanks,

Kevin

See Working with XML in Android for a variety of methods for dealing with XML. Which method to use depends on how big your XML is, and what you want to do with it. '

I'm not sure how it makes any sense to turn XML into an array, so no, none of the methods do that. If you want something similar to that, use Json instead of XML.

After a bit of research, it appears to me that using the Simple XML Serialization framework is going to be my best bet, especially since I do have a relatively simple XML file to read. The result will be a 'list' class with several 'entry' classes which seems like a viable way to handle this...probably better than having an array of classes as was done in the iPhone app.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM