New to Objective C - and wanting to access a sql server web service.

Discussion in 'Mac Programming' started by sshouler, Oct 15, 2012.

  1. sshouler, Oct 15, 2012
    Last edited by a moderator: Oct 15, 2012

    sshouler macrumors newbie

    Joined:
    Oct 15, 2012
    #1
    The code below retrieves web service data but I want to be able to loop through the 11 elements and display each text and value item.

    The following code:

    Code:
    #define WcfServiceURL [NSURL URLWithString: @"http://api.silentpassenger.com/rest/v2/A0000015EA7F4E/vehiclenames?userid=238"]  //good
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
    
        NSURL *url = [NSURL                  URLWithString:@"http://api.silentpassenger.com/rest/v2/A0000015EA7F4E/vehiclenames?userid=238"];
    
        NSError *error = nil;
        NSData *data = [NSData dataWithContentsOfURL:WcfServiceURL options:NSDataReadingUncached error:&error];
        
        NSString *strData = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding]; //good
        
        NSLog(@"%@",strData.uppercaseString); //good
    }
    strData provides the following data...


    Code:
    <ARRAYOFTEXTVALUE XMLNS="HTTP://SCHEMAS.DATACONTRACT.ORG/2004/07/VTS.BUSINESS" XMLNS:I="HTTP://WWW.W3.ORG/2001/XMLSCHEMA-INSTANCE"><TEXTVALUE><TEXT>A. ROSS</TEXT><VALUE>17447</VALUE</TEXTVALUE><TEXTVALUE><TEXT>F-1</TEXT><VALUE>21784</VALUE></TEXTVALUE><TEXTVALUE><TEXT>H-1</TEXT><VALUE>2008</VALUE></TEXTVALUE><TEXTVALUE><TEXT>H-2</TEXT><VALUE>18435</VALUE></TEXTVALUE><TEXTVALUE><TEXT>H-3</TEXT><VALUE>18780</VALUE></TEXTVALUE><TEXTVALUE><TEXT>H-4</TEXT><VALUE>26550</VALUE></TEXTVALUE><TEXTVALUE><TEXT>H-5</TEXT><VALUE>26551</VALUE></TEXTVALUE><TEXTVALUE><TEXT>JEEP007</TEXT><VALUE>15776</VALUE</TEXTVALUE><TEXTVALUE><TEXT>PETE</TEXT><VALUE>28371</VALUE></TEXTVALUE><TEXTVALUE<TEXT>STEVE'S LT</TEXT<VALUE>2221</VALUE</TEXTVALUE>
    <TEXTVALUE><TEXT>STEVE'S/DANNY JEEP</TEXT><VALUE>15905</VALUE></TEXTVALUE>
    </ARRAYOFTEXTVALUE>
    What modifications need I make to this code to display the elements like this:
    A. Ross 17447
    F-1 21784
    H-1 2008
    H-2 18435
    H-3 18780
    . .
    . .
    . .

    Thanks in advance!!!
     
  2. Ap0ks macrumors 6502

    Joined:
    Aug 12, 2008
    Location:
    Cambridge, UK
    #2
    You'll probably want to use NSXMLParser, there are plenty of tutorials on Google, or there is a decent section on XML Parsing at the Apple Developer site.
     

Share This Page