2013-03-29 2 views
0

xml 응답을 포함하는 문자열이 있습니다 (asmx 웹 서비스) xml을 APXML 라이브러리를 통해 구문 분석합니다. 내가 body 태그를주고 루트 요소를 얻을 때 body 태그를 원하지 않는다. 루트 태그와 자식 태그보다 실제 데이터를 얻고 싶다 .. 이 데이터를 얻는 방법을 알려주세요 .. thanks .. 내 XML은 iPhone에서 XML을 구문 분석하는 방법

<?xml version="1.0" encoding="UTF-8" ?> 
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> 
<soap:Body> 
<loginFunctionResponse xmlns="http://tempuri.org/"> 
    <loginFunctionResult> 
    <Root xmlns=""> 
    <child> 
    <id>52</id> 
    <name>mohsin</name> 
    </child> 
    </Root> 
</loginFunctionResult> 
</loginFunctionResponse> 
</soap:Body> 
</soap:Envelope> 

이며, 내 코드는 ... 내가이 결과를 제공

NSString *resultString=[[NSString alloc] initWithBytes:[resultData bytes] length:resultData.length encoding:NSUTF8StringEncoding]; 
NSLog(@"result string: %@",resultString); 

APDocument *doc = [APDocument documentWithXMLString:resultString]; 

APElement *rootElement = [doc rootElement]; 
NSArray *childElement = [rootElement childElements]; 

for (APElement *chile in childElement) { 


    NSLog(@"chid name %@",chile.name); 
    NSLog(@"chile value %@",chile.value); 
} 

..

chid name soap:Body 
chile value (null) 
+1

XML 요소에는 값이없고 단순히 다른 자식이 있습니다. – borrrden

+0

하위 태그 요소를 가져 오는 방법은 무엇입니까? 감사합니다 –

+2

당신은 spoonfed 필요합니까? 루트 요소에서 하위 요소를 얻은 방법을 살펴보고 해당 논리를 적용하십시오. – borrrden

답변

2

childElements은 재귀 적이 아니며 루트 요소의 직접 자손 만 반환합니다.

이 경우 유일한 자식 요소는 내용이없고 자식이 하나이기 때문에 값이 null 인 태그 <loginFunctionResponse xmlns="http://tempuri.org/">입니다.

전체 트리를 구문 분석하려면 자식 (자식이없는 요소)에 도착할 때까지 모든 자식에서 재귀 호출 childElements을 호출해야합니다.

+0

전체 트리를 구문 분석하는 방법에 대한 링크를 제공하면 ios에서 초보자입니다. 덕분에 –

+0

이것은 iOS에 관한 것이 없습니다. 일반적인 프로그래밍입니다. –

관련 문제