views:

191

answers:

1

Hi everyone, i've another problem with obj-c: i'm trying to parse this XML :

here's the case:

<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;&lt;soap:Body&gt; <GetMyDashboardResponse xmlns="http://tempuri.org/"&gt; <GetMyDashboardResult> <MyDashboard><Profile>Speed Seeker</Profile> <UserID>6</UserID> <VenueName>Prasowa</VenueName> <FriendsCount>10</FriendsCount> <FollowingCount>11</FollowingCount> <FollowersCount>12</FollowersCount> <StatusMessage>aaa</StatusMessage> <StatusDate>2010-08-04T11:38:09.733</StatusDate> <CheckedInTimeStamp>2010-07-30T13:48:24</CheckedInTimeStamp> </MyDashboard> </GetMyDashboardResult> </GetMyDashboardResponse></soap:Body></soap:Envelope> , and here's how i'm trying to accomplish it:

`

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

CXMLDocument *doc = [[[CXMLDocument alloc] initWithData:XMLData options:0 error:nil] autorelease];

NSArray *nodes = NULL;
nodes = [doc nodesForXPath:@"//MyDashboard" error:nil];

for (CXMLElement *node in nodes) 
{
      NSMutableDictionary *item = [[NSMutableDictionary alloc] init];
      int counter;
      for(counter = 0; counter < [node childCount]; counter++) 
      {
            [item setObject:[[node childAtIndex:counter] stringValue] forKey:[[node childAtIndex:counter] name]];
      }
      [item setObject:[[node elementsForName:@"Profile"] stringValue] forKey:@"profileName"];  // <------ this magical arrow is pointing to the area of interest
    NSLog(@"petla");
      [res addObject:item];
      [item release];
}

NSLog(@"%@", res);
[res release];

`

thanks for any help. mapedd

A: 

[node elementsForName] will return NSArray, so you definitely can't use stringValue on that. Create temporary NSArray, set elementsForName to it, check if its object count > 0, take objectAtIndex:0 and you're good to go!

sniurkst