-1

Let's say I have the following string:

NSString * str = "<a href="http://www.google.com"style="">
</br>
<a href="http://www.google.com" id="" style="">Come on</a>hello world"

How can I parse out the value of the anchor tag--"Come on"?

Should I use HTMLNode.h and HTMLParser.h? Examples would be appreciated.

rbbtsn0w
  • 75
  • 11
  • Please take a look at this thread - http://stackoverflow.com/questions/2712213/html-agility-pack-like-solutions-for-c-objective-c-iphone – KV Prajapati Aug 17 '11 at 11:28

1 Answers1

1

If it is static, then you can use string manipulation to take out the substring out of the tag

OR

If it is dynamic and html/xml code keeps changing then you can use NSXMLParser. Keep in mind that NSXMLParser should more preferably used only when data is in XML format.

http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSXMLParser_Class/Reference/Reference.html

Hope this helps.

Parth Bhatt
  • 19,381
  • 28
  • 133
  • 216
  • hi , Parth Bhatt. thank you ,but i want know how to use it ! you know ,it's static , i know use the tag '', but the '' tag , so.. – rbbtsn0w Aug 17 '11 at 08:10
  • @FlyProgramer2Ball: May I know what difficulty you face in implementing NSXMLParser or the static method as I have mentioned? – Parth Bhatt Aug 17 '11 at 08:16
  • `substringFromIndex:` and `substringToIndex:` method of NSString class might be useful. For more info on this check out http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html – Parth Bhatt Aug 17 '11 at 08:18
  • thanks for your link. The string values is static , looks like. but the value is return of the server client . so the string is dynamic , i can't use subStringToIndex . – rbbtsn0w Aug 17 '11 at 08:26
  • @FlyProgramer2Ball: Here we can just guide you through. This is a community where we only encourage exchange of good ideas. Here we should not expect someone to give the whole code from a to z. Actually for finding readymade codes and tutorials, you may search on Google. Here only a hint or a direction should be fine. And after searching on google if you dont find a proper tutorial then you may ask for one here on StackOverflow. Hope you get it. Thanks :) – Parth Bhatt Aug 17 '11 at 10:14
  • OK, thank you @Parth Bhatt. but you misunderstood me , i don't give code from a to z. – rbbtsn0w Aug 19 '11 at 01:29