0

i want to parse a xhtml file and display in UITableView. what is the best way to parse xhtml file so that i could be able to display as it is shown in browser. here is a sample xhtml source

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xml:lang="en-US" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Wheel</title>
<link rel="stylesheet" type="text/css" href="../styles/stylesheet.css"/>
<link rel="stylesheet" type="application/vnd.adobe-page-template+xml" href="../page-template.xpgt"/>
</head>
<body>
<h2 class="h2"><a id="page_x"></a><a id="page_xi"></a><a id="page_xii"></a><a id="table"></a>TABLE OF CONTENTS</h2>
<p class="content2"><strong><a href="Big Idea.html">WHAT&#8217;S THE BIG IDEA?</a></strong></p>
<p class="content2"><strong><a href="Choosing.html">CHOOSING</a></strong></p>
<p class="content2"><strong><a href="author note.html">AUTHOR&#8217;S NOTE</a></strong></p>
<p class="content2"><strong><a href="part1.html">THE STORY OF OG</a></strong></p>
<p class="content"><a href="chapter01.html">Chapter &#35;&#160; 1:&#160;&#160;Og Gets an Idea</a></p>
<p class="content"><a href="chapter02.html">Chapter &#35;&#160; 2:&#160;&#160;Dazed By the Possibilities</a></p>
<p class="content"><a href="chapter03.html">Chapter &#35;&#160; 3:&#160;&#160;Aargh!</a></p>
<p class="content"><a href="chapter04.html">Chapter &#35;&#160; 4:&#160;&#160;The Grunt of the Town</a></p>
<p class="content"><a href="chapter05.html">Chapter &#35;&#160; 5:&#160;&#160;Getting Around To It</a></p>
<p class="content"><a href="chapter05.html">Chapter &#35;&#160; 6:&#160;&#160;Og&#8217;s Head Is Full, But the Cupboard Is Empty</a></p>
<p class="content"><a href="chapter07.html">Chapter &#35;&#160; 7:&#160;&#160;The Big Meating</a></p>
<p class="content"><a href="chapter08.html">Chapter &#35;&#160; 8:&#160;&#160;The Path Is Made By Walking On It</a></p>
<p class="content"><a href="chapter09.html">Chapter &#35;&#160; 9:&#160;&#160;Crouch</a></p>
<p class="content"><a href="chapter10.html">Chapter &#35;10:&#160;&#160;An Arrow to the Heart of the Matter</a></p>
<p class="content"><a href="chapter11.html">Chapter &#35;11:&#160;&#160;Nothing to Get</a></p>
<p class="content"><a href="chapter12.html">Chapter &#35;12:&#160;&#160;Smoke From a Fire, Flakes From a Stone</a></p>
<p class="content"><a href="chapter13.html">Chapter &#35;13:&#160;&#160;The Happy Accident</a></p>
<p class="content"><a href="chapter14.html">Chapter &#35;14:&#160;&#160;The Center Is Everything</a></p>
<p class="content"><a href="chapter15.html">Chapter &#35;15:&#160;&#160;Sleeping Like a Rock</a></p>
<p class="content"><a href="chapter16.html">Chapter &#35;16:&#160;&#160;Follow Your Feet</a></p>
<p class="content"><a href="chapter17.html">Chapter &#35;17:&#160;&#160;Everyone&#8217;s Turn</a></p>
<p class="content2"><a href="Best Practices.html"><strong>WHAT OG LEARNED:</strong> 12 Wheely Good Best Practices</a></p>
<p class="content2"><a href="Tooling.html"><strong>TOOLING UP:</strong> 35 Ways to Get the Wheels Turning</a></p>
<p class="content2"><a href="stone.html"><strong> IN STONE:</strong> The Tools and Techniques Contest</a></p>
<p class="content2"><a href="Nexting.html"><strong>NEXTING:</strong> the Future</a></p>
<p class="content2"><a href="Staying.html"><strong> ROLL:</strong> Resources for Thinking Outside the Cave</a></p>
<p class="content2"><a href="ogcasting.html"><strong>O<span class="smallcaps2">G</span>CASTING:</strong> Your Free Audio Bonus</a></p>
<p class="content2"><a href="about_author.html"><strong>ABOUT THE AUTHOR</strong></a></p>
</body>
</html>

2 Answers 2

1

I would strongly recommend using libxml2 for parsing html or xhtml. I followed this tutorial http://cocoawithlove.com/2008/10/using-libxml2-for-parsing-and-xpath.html but took few iterations to get the loops going properly.

Another good approach would be to create a web service of your own that does xhtml parsing on the server side and returns well structured json result. This way you are in control of parsing in case something changes to the html structure you could easily update your parser on the server side (there by avoiding going through another app update process).

0

Another approach is using UIWebView, let it use only to load the Document and make use of DOM Class to access Data

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.