1

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.

Mahesh Babu
  • 3,395
  • 9
  • 48
  • 97
  • Why are you writing apps for iPhone OS 2.0? Do you mean 3.0? – Brian Donovan Jan 11 '11 at 16:16
  • 2
    -1 for not searching first SO for similar questions. – Moszi Jan 11 '11 at 16:20
  • 2
    @Moszi I disgree with the downvote, I picked up on the part about them currently using NSXMLParser and wondering about its iOS2.0 compatibility, rather than the later question about other methods, which would indeed warrant some search function education. Instead of shunning them, I thought it would be better to actually try and solve their iOS version problem. – badgerr Jan 11 '11 at 16:25
  • 1
    In which case i would downvote the question for not simple Option-DoubleClicking NSXMLParser in XCode and reading the "Availability: iOS 2.0 and later" text ... – Moszi Jan 11 '11 at 16:28
  • People don't come to SO to be told simply to "RTFM". At least, I like to think we are more helpful than that. =) – badgerr Jan 11 '11 at 16:30
  • On the other hand - i think you are right, and the question was about an entirely different thing: NSXMLParserDelegate ... Probably i should just stop downvoting anyway because of RTFM ... :) – Moszi Jan 11 '11 at 16:35
  • The docs are a bit confusing in this case. The delegate methods were available in 2.0 but the protocol wasn't "formally" declared until 4.0. See [this](http://stackoverflow.com/questions/2966475/nsxmlparserdelegate-compile-problem-iphone-sdk-30-vs-4-0), [this](http://stackoverflow.com/questions/2302476/is-there-a-difference-between-only-nsxmlparserdelegate-only-setdelegate-method), and [this](http://stackoverflow.com/questions/3081595/nsxmlparserdelegate-and-iphone-sdk-3-1-x). –  Jan 11 '11 at 16:35

4 Answers4

2

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
Moszi
  • 3,236
  • 2
  • 22
  • 20
1

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
PeyloW
  • 36,742
  • 12
  • 80
  • 99
0

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

Alex Terente
  • 12,006
  • 5
  • 51
  • 71
0

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.

badgerr
  • 7,802
  • 2
  • 28
  • 43
  • NSXMLParserDelegate has been available since iOS 2.0 (I've been using it since then). The availability documentation is a bit odd, but for the methods it says: Available in iOS 2.0 and later. Available as part of an informal protocol prior to iOS 4.0. – mluisbrown Jan 11 '11 at 16:27
  • @mluisbrown Thanks for the confirmation. – badgerr Jan 11 '11 at 16:28