繁体   English   中英

如何解析iPhone中的xml,

[英]how to parse xml in iPhone ,

我有包含xml responce的字符串,(asmx web服务)我正在通过APXML lib解析xml。 当我得到根元素给我身体标签,我不想要身体标签,我想得到我的实际数据,在Root标签和子标签..请告诉我如何从这里获取数据..谢谢..我的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)

childElements不是递归的,它只返回根元素的直接后代。

因此,在这种情况下,唯一的子元素是标记<loginFunctionResponse xmlns="http://tempuri.org/"> ,其值为null,因为它没有任何内容,只有一个子元素。

如果你想解析整个树,你应该递归地调用每个孩子的childElements ,直到你到达叶子(没有孩子的元素)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM