2010-06-29 8 views
0

xhtml 파일을 구문 분석하고 UITableView에 표시하려고합니다. xhtml 파일을 구문 분석하여 브라우저에 표시되는 것처럼 표시 할 수있는 가장 좋은 방법은 무엇입니까? 다음은 샘플 xhtml 소스입니다.iphone sdk에서 xhtml을 구문 분석 하시겠습니까?

<?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> 

답변

1

html 또는 xhtml을 구문 분석 할 때 libxml2를 사용하는 것이 좋습니다. 이 튜토리얼 http://cocoawithlove.com/2008/10/using-libxml2-for-parsing-and-xpath.html을 따라 갔지만 루프가 올바르게 진행되도록하려면 몇 번의 반복 작업을 수행했습니다.

또 다른 좋은 방법은 서버 측에서 xhtml 구문 분석을 수행하고 잘 구조화 된 json 결과를 반환하는 자체 웹 서비스를 만드는 것입니다. 이렇게하면 html 구조가 변경되어 서버 측에서 파서를 쉽게 업데이트 할 수 있으므로 구문 분석을 제어 할 수 있습니다 (다른 응용 프로그램 업데이트 프로세스를 거치지 않아도 됨).

0

또 다른 접근 방식은 UIWebView를 사용하여 문서를로드하고 DOM 클래스를 사용하여 데이터에 액세스합니다.

관련 문제