这是一个创建于 3256 天前的主题,其中的信息可能已经有所发展或是发生改变。
要解析的 XML 数据如下,我把它转成字符串如下:
<?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>
<getWeatherbyCityNameResponse
xmlns="http://WebXml.com.cn/">
<getWeatherbyCityNameResult>
<string>56492</string>
<string>2015-11-21 22:18:14</string>
<string>17℃/21℃</string>
<string>11 月 21 日 多云转小雨</string>
</getWeatherbyCityNameResult>
</getWeatherbyCityNameResponse>
</soap:Body>
</soap:Envelope>
那么问题来了,无论我用 GDataXML 解析还是 NSXMLParser 都解析不出<string>XXXXX</string>中间那个 XXXXX 那个字符串, NSXMLParser 解析实现如下:
//xmlData 是我请求的得到的数据
NSXMLParser *parser = [[NSXMLParser alloc] initWithData:xmlData];
parser.delegate = self;
[parser parse];
在代理方法:
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
NSLog(@"%@-----%@-----%@----%@", elementName, namespaceURI, qName, attributeDict);
}
打印结构如下:
2015-11-21 22:25:05.713 ChangHang[611:23462] string-----(null)-----(null)----{
}
9 条回复 • 2015-11-23 14:20:09 +08:00
|
|
1
lfflyers 2015-11-21 23:09:30 +08:00
大神都睡了吗?
|
|
|
2
targz 2015-11-22 01:02:49 +08:00 via Android
代理方法不是一个,开始之后还有其它方法的,有个什么 characters 的
|
|
|
3
expkzb 2015-11-22 10:34:17 +08:00 via iPhone
搞 soap 有专用的解析,何苦那么累
|
|
|
4
lfflyers 2015-11-22 12:45:11 +08:00
@ targz 好像在哪个方法里有值,之前一直没用过~~
|
|
|
6
nellace 2015-11-22 22:14:57 +08:00
|
|
|
7
nellace 2015-11-22 22:16:00 +08:00
|
|
|
8
18ac0877 2015-11-23 12:39:56 +08:00
终极武器 直接查找字符串
|