views:

222

answers:

1

Question: Is this an appropriate way to parse HTML into a plist?

I need to pull information from the following html. The HTML is in this style consistently. The first block of HTML is a section header and the second part is the sections content. The sections can have any number of contents.

This is the HTML.

<td class="boxcontainer">
<div class="">
  <div class="titlebox" id="">
  <div class="titlebox-title">
    <span class="widget"><a href="#" 
 onclick="return rollup('TitleBox--_index.html------MjUgbmV3ZXN0IHVub3duZWQgdGlja2V0cw==---0');" 
 title="Toggle visibility"></a>
 </span>
    <span class="left">
       <a href="/Search/Results.html?Format='%3Ca%20href%3D%22%2FTicket%2FDisplay.html%3Fid%3D__id__%22%3E__id__%3C%2Fa%3E%2FTITLE%3A%23'%2C%20'%3Ca%20href%3D%22%2FTicket%2FDisplay.html%3Fid%3D__id__%22%3E__Subject__%3C%2Fa%3E%2FTITLE%3ASubject'%2C%20QueueName%2C%20ExtendedStatus%2C%20CreatedRelative%2C%20'%3CA%20HREF%3D%22%2FTicket%2FDisplay.html%3FAction%3DTake%26id%3D__id__%22%3ETake%3C%2Fa%3E%2FTITLE%3A%26nbsp%3B'%20&Order=DESC&OrderBy=Created&Query=%20Owner%20%3D%20'Nobody'%20AND%20(%20Status%20%3D%20'new'%20OR%20Status%20%3D%20'open')">25 newest unowned tickets</a></span>
    <span class="right">
 <a href="/Prefs/Search.html?name=RT%3A%3AAttribute-2">
 Edit</a>
    </span>
  </div>
  <div class="titlebox-content " id="TitleBox--_index.html------MjUgbmV3ZXN0IHVub3duZWQgdGlja2V0cw==---0">



<table border="0" cellspacing="0" cellpadding="1" width="100%" class="ticket-list"><tr class="collection-as-table">
<th class="collection-as-table">#</th><th class="collection-as-table">Subject</th><th class="collection-as-table">Queue</th><th class="collection-as-table">Status</th><th class="collection-as-table">Created</th><th class="collection-as-table">&nbsp;</th></tr>
<tr class="oddline" >
<td class="collection-as-table" align="right"><a href="/Ticket/Display.html?id=19773">19773</a></td>
<td class="collection-as-table" ><a href="/Ticket/Display.html?id=19773">Web form help request: IT-Email Problem</a></td>
<td class="collection-as-table" >General</td>
<td class="collection-as-table" >new</td>
<td class="collection-as-table" >2 days ago</td>
<td class="collection-as-table" align="right"><a href="/Ticket/Display.html?Action=Take&amp;id=19773">Take</a></td>

My plan is to use NSScanner to find "widget" and then find "href=" then locate the next ">" and capture all characters before the "<" and write it to the plist as the section title.

Repeat over and over until I find "widget" again: { find the next "href=" and go to the next ">" capture all characters before "<" write as a detail to plist...

Go to next "href=" go to ">" capture characters before "<" write to plist as details title. }

I havnt started coding this as I'm new to this language and I'm trying to come up with a real plan that makes sense. Does this make sense?

A: 

You need a proper parser to reliably parse an HTML document. To convert an HTML document into a property list (plist), you are probably better off using a SAX parser. NSXMLParser is an SAX parser included in both MacOS and iOS SDKs.

I find this post useful in identifying an XML parser for objective-c.

William