作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有包含 xml 响应的字符串,(asmx 网络服务)我正在通过 APXML 库解析 xml。当我得到给我 body 标签的根元素时,我不想要 body 标签,我想得到我在 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,因为它没有任何内容,只有一个 child 。
如果要解析整棵树,应该递归调用childElements
在每个 child 上,直到你到达叶子(没有 child 的元素)。
关于iphone - 如何在 iPhone 中解析 xml,,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15698439/
我是一名优秀的程序员,十分优秀!