Mahesh Babu
Mahesh Babu

Reputation: 3433

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 NSXMlparsing 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.

Upvotes: 1

Views: 1153

Answers (4)

PeyloW
PeyloW

Reputation: 36762

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

Upvotes: 1

Moszi
Moszi

Reputation: 3236

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

Upvotes: 2

Alex Terente
Alex Terente

Reputation: 12036

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

Upvotes: 0

badgerr
badgerr

Reputation: 7982

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.

Upvotes: 0

Related Questions