开发者

How to parse xml string in iphone 2.0

I am getting information (id,name,address) in the form of xml string form the .net web server.

i am using NSXMlpa开发者_运维知识库rsing to parse this xml string in iphone os 4.0.

Now i need to do the same application in iphone os 2.0.

i found Nsxmlparsing delegate should work on 4.0 and later.

Can any one please suggest which method is suitable to parse xml string and sample tutorial.

Thank u in advance.


NSXMLParserDelegate was added in iOS 4.0. You can declare that protocol with a #define directive to include the protocol declaration in iOS versions before 4.0 to be able to compile your code, but you don't necessarily have to include all methods in this protocol definition.
You can do something like this:

#if __IPHONE_OS_VERSION_MAX_ALLOWED < __IPHONE_4_0

@protocol NSXMLParserDelegate <NSObject>
@end

#endif


NSXMLParser has been available since iPhone OS 2.0. The delegate protocol has always been available as well, but prior to iOS 4.0 NSXMLParserDelegate was what is called an informal protocol, e.g. not explicitly defined.

As of iOS 4.0 many protocols that where previously informal has been promoted to actual format protocols, NSXMLParserDelegate is one of them.

The warning you get about not conforming to the protocol is building against SDK 4.0 and later, or missing protocol if building against an earlier SDK can be remedied by conforming to the protocol conditionally as such:

@interface MyClass : NSObject
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_4_0
    <NSXMLParserDelegate>
#endif
{
   // Your ivars here
}
// And methods here as usual
@end

Or you can make the compiler shut up by casting your delegate to id when setting it like this:

[myXMLParser setDelegate:(id)self];  // Assuming self is the delegate


Edited: NSXMLParser from doc Availability Available in iOS 2.0 and later.


According to the NSXMLParser documentation, you can use it with iOS 2.0. The delegate documentation mentions iOS4. One of these is wrong, and I don't have an iOS 2.0 device to test this on, but have you tried your app in its current form? My assumption here is that the delegate documentation is wrong, and it does infact have support on 2.0.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜