V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
iOS 开发实用技术导航
NSHipster 中文版
http://nshipster.cn/
cocos2d 开源 2D 游戏引擎
http://www.cocos2d-iphone.org/
CocoaPods
http://cocoapods.org/
Google Analytics for Mobile 统计解决方案
http://code.google.com/mobile/analytics/
WWDC
https://developer.apple.com/wwdc/
Design Guides and Resources
https://developer.apple.com/design/
Transcripts of WWDC sessions
http://asciiwwdc.com
Cocoa with Love
http://cocoawithlove.com/
Cocoa Dev Central
http://cocoadevcentral.com/
NSHipster
http://nshipster.com/
Style Guides
Google Objective-C Style Guide
NYTimes Objective-C Style Guide
Useful Tools and Services
Charles Web Debugging Proxy
Smore
lfflyers
V2EX  ›  iDev

iOS XML 解析不出来,尝试了各种方法都一样,有没有大神碰到过类似的情况,求指教!!!

  •  1
     
  •   lfflyers · 2015-11-21 22:39:05 +08:00 · 3131 次点击
    这是一个创建于 3069 天前的主题,其中的信息可能已经有所发展或是发生改变。
    要解析的 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
    lfflyers
        1
    lfflyers  
    OP
       2015-11-21 23:09:30 +08:00
    大神都睡了吗?
    targz
        2
    targz  
       2015-11-22 01:02:49 +08:00 via Android
    代理方法不是一个,开始之后还有其它方法的,有个什么 characters 的
    expkzb
        3
    expkzb  
       2015-11-22 10:34:17 +08:00 via iPhone
    搞 soap 有专用的解析,何苦那么累
    lfflyers
        4
    lfflyers  
    OP
       2015-11-22 12:45:11 +08:00
    @targz 好像在哪个方法里有值,之前一直没用过~~
    lfflyers
        5
    lfflyers  
    OP
       2015-11-22 12:45:33 +08:00
    @expkzb 不都是 XML 数据吗~~
    nellace
        6
    nellace  
       2015-11-22 22:14:57 +08:00
    nellace
        7
    nellace  
       2015-11-22 22:16:00 +08:00
    @expkzb 还真没用过,推荐一下呗
    18ac0877
        8
    18ac0877  
       2015-11-23 12:39:56 +08:00
    终极武器 直接查找字符串
    scfhao
        9
    scfhao  
       2015-11-23 14:20:09 +08:00
    @nellace
    @lfflyers
    见过两个封装了 soap 的库,一个叫 wsdl2objc ,另一个叫 sudzc ( http://sudzc.com )。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1025 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 19:40 · PVG 03:40 · LAX 12:40 · JFK 15:40
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.