Florian Schaal
Florian Schaal

Reputation: 2660

Importing data from server txt/xml

I'm currently developing an app that will be used as track and trace app. This app will need data that is located on a server. Let's say, we create a file for each customer on the server. This file will contain the track and trace info. Would it be easier if this is a xml file or text file and how would the code look like?

Let's say we've already knew the customers number and the file has the same name as the customer number. The user tapped the button to get the data. Then the app contacts the server asking for the file that got the same customers number and reads it presenting the info in a label or something similar.

Any suggestions where to start?

Upvotes: 1

Views: 98

Answers (1)

Ivan Alek
Ivan Alek

Reputation: 1919

If you dont have any other specific requirements fetching xml files from server will be good enough. For example if you have file at url www.test.com/user1.xml you can load into data

NSData *tmpData = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"www.test.com/user1.xml"] ];
                    //convert data to string
NSString *tmpString = [[NSString alloc] initWithData:tmpData encoding:NSUTF8StringEncoding];
NSArray *piecesArray = [tmpString componentsSeparatedByString:@" "];
if(piecesArray.count==2)
{
   labelA.text = [piecesArray objectAtIndex:0];
   labelB.text = [piecesArray objectAtIndex:1];
}

Upvotes: 1

Related Questions