2010-08-04 7 views
3

난 OBJ-C의 또 다른 문제했습니다 : 내가이 XML 구문 분석하려고 해요 : 여기구문 분석 SOAP 응답 - 문제

을 경우의 방법은 다음과 같습니다

<?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"> 
    <soap:Body> 
     <GetMyDashboardResponse xmlns="http://tempuri.org/"> 
      <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> 

와 나는 '그것을 달성하기 위해 노력하고있어 : 어떤 도움

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]; 

`

감사합니다.

답변

1

[node elementsForName]NSArray을 반환하므로 분명히 stringValue을 사용할 수 없습니다. 임시 NSArray을 만들고 elementsForName으로 설정하고 개체 수가 0보다 큰 지 확인한 후 objectAtIndex:0을 입력하면됩니다.