【发布时间】:2013-03-29 06:26:28
【问题描述】:
我有包含 xml 响应的字符串,(asmx Web 服务) 我正在通过 APXML lib 解析 xml。 当我得到给我身体标签的根元素时,我不想要身体标签,我想获得根标签中的实际数据而不是子标签.. 请告诉我如何从中获取数据.. 谢谢.. 我的 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)
【问题讨论】:
-
那个 XML 元素没有价值,它只是有另一个孩子。
-
如何获取子标签元素?谢谢
-
你需要用勺子喂它吗?查看如何从根元素获取子元素并应用该逻辑。
-
@mohsinraza 看看我的回答。您只需对每个孩子递归调用
childElements,直到他们不再有孩子
标签: iphone ios xml xml-parsing