FROM : Jens Alfke
DATE : Thu May 15 06:22:34 2008
On 14 May '08, at 4:25 PM, Mr. Gecko wrote:
> <a href="example.com" title="Ttitle">text I want</a>
> so I want to get the text in the middle of points title="Ttitle">
> and </a>
Trying to parse HTML by hand like this is a good way to lose your
mind. Seriously, don't try it. Simple searching through strings
looking for delimiters doesn't always work, due to quoting and things
like that. The only way to do it reliably is to write a parser that
knows the rules of HTML, and even then you have to deal with the fact
that many, many websites are full of really broken HTML.
And you don't need to do that, when NSXML will do the parsing for you.
Learn XPath and you can extract things like your example in one line
of code.
> I have heard of NSRange but I can't find documentation to it in xcode.
Just open the documentation window and type "NSRange" into the search
field.
Or find the word NSRange in an editor window and option-double-click it.
Or go here:
file:///Developer/Documentation/DocSets/com.apple.ADC_Reference_Library.CoreReference.docset/Contents/Resources/Documents/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_DataTypes/Reference/reference.html
#//apple_ref/doc/uid/20000018-DontLinkElementID_14
—Jens
DATE : Thu May 15 06:22:34 2008
On 14 May '08, at 4:25 PM, Mr. Gecko wrote:
> <a href="example.com" title="Ttitle">text I want</a>
> so I want to get the text in the middle of points title="Ttitle">
> and </a>
Trying to parse HTML by hand like this is a good way to lose your
mind. Seriously, don't try it. Simple searching through strings
looking for delimiters doesn't always work, due to quoting and things
like that. The only way to do it reliably is to write a parser that
knows the rules of HTML, and even then you have to deal with the fact
that many, many websites are full of really broken HTML.
And you don't need to do that, when NSXML will do the parsing for you.
Learn XPath and you can extract things like your example in one line
of code.
> I have heard of NSRange but I can't find documentation to it in xcode.
Just open the documentation window and type "NSRange" into the search
field.
Or find the word NSRange in an editor window and option-double-click it.
Or go here:
file:///Developer/Documentation/DocSets/com.apple.ADC_Reference_Library.CoreReference.docset/Contents/Resources/Documents/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_DataTypes/Reference/reference.html
#//apple_ref/doc/uid/20000018-DontLinkElementID_14
—Jens
| Related mails | Author | Date |
|---|---|---|
| Mr. Gecko | May 15, 01:25 | |
| Randall Meadows | May 15, 01:33 | |
| Mr. Gecko | May 15, 01:39 | |
| Andy Lee | May 15, 01:48 | |
| Jens Alfke | May 15, 06:22 |






Cocoa mail archive

