0

I am new to xml parsing. I have the following xml

<myMainList>
            <mySubList>
              <edited>true</edited>
              <mySharedNumber>W59QYBZKJ4</mySharedNumber>
           </mySubList>
           <mySubList>
              <edited>false</edited>
              <mySharedNumber>TOW4KLP9WD</mySharedNumber>
           </mySubList>
           <mySubList>
              <edited>true</edited>
              <mySharedNumber>XH8JDIZA64</mySharedNumber>
           </mySubList>
           <mySubList>
              <edited>false</edited>
              <mySharedNumber>V2YOHSNODT</mySharedNumber>
           </mySubList>
   </myMainList>

I have edited my question.

I am not familiar with looping through the whole xml and adding the values into my array. Can someone show me how I can add the 4 sharedNumberList values into my array.

Edit:

GDataXMLElement *node;

2 Answers 2

1
NSArray * array = [node nodesForXPath:@"//return/myMainList/mySubList" error:nil];
            NSLog(@"count  :%d",[array count]);
            int sharedContacts = [array count];

            NSMutableArray *mySharedListArray = [[NSMutableArray alloc]init];


      for(int i = 1; i<= sharedContacts; i++){
                NSString *xmlDataFetcher = [NSString stringWithFormat:@"//return/myMainList/mySubList[%d]",i ];
                NSString *parsedNumbers = [node nodeStringForXPath:[xmlDataFetcher stringByAppendingString:@"/mySharedNumber"]];
                NSString *parsedEdit = [node nodeStringForXPath:[xmlDataFetcher stringByAppendingString:@"/edited"]];
                NSLog(@"Parsed Edited %@", [node nodeStringForXPath:[xmlDataFetcher stringByAppendingString:@"/edited"]]);
                NSLog(@"Parsed sharedNumber %@", [node nodeStringForXPath:[xmlDataFetcher stringByAppendingString:@"/mySharedNumber"]]);
                NSString *arrayEntry = [NSString stringWithFormat:@"%@%@", parsedNumbers, parsedEdit];;

                [mySharedListArray addObject:arrayEntry]; 
            }
            NSLog(@"Array entry %@", mySharedListArray);

I have added a lot of NSLog in the answer, so that you could log it as you wish

Sign up to request clarification or add additional context in comments.

Comments

0

I haven't done this most probably this is returning an array from the xpath query so Try this instead

[mySharedListArray addObjectsFromArray:[node nodesForXPath:@"//return/MyList" error:nil]];

3 Comments

It shows incompatible pointer types sending 'NSString *' to parameter of type 'NSArray *'
@JeanPaulScott please look at my edit... this will surely work.
The nodesForXPath method also has an NSError ** parameter.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.