2014-02-08 3 views
0

저는 iOS 용 일일 응용 프로그램의 성경 인용문을 작성 중이며 XML 데이터를 구문 분석하여 응용 프로그램의 UITextView에 온라인으로 표시 할 수 있는지 궁금합니다.웹 사이트의 XML 파일을 UITextView로 구문 분석합니다.

<bible> 
<title>John 1:14</title> 
<item> 
<bookname>John</bookname> 
<chapter>1</chapter> 
<verse>14</verse> 
<text> 
Now the Word became flesh and took up residence among us. We saw his glory – the glory of the one and only, full of grace and truth, who came from the Father. 
</text> 
</item> 
<results>1</results> 
</bible> 

나는 다른 UITextViewUITextView<text><title>을 구문 분석 생각 해요. 아무도 이것으로 도울 수 있습니까? Apple의 NSXMLParser을 사용할 수 있습니까?

+0

아마도 도움이 될 수 있습니다. http://stackoverflow.com/a/9884929/1153630 –

답변

1

결과 수가 항상 이면 필요한 필드를 얻기 위해 문자열을 분할 할 수 있습니다.

예를 들어, XML 문자열,

코드 나는 보통 XML이 lib 디렉토리를 구문 분석하는 데 사용

NSString *data = @"<bible><title>John 1:14</title><item><bookname>John</bookname><chapter>1</chapter> <verse>14</verse> <text> Now the Word became flesh and took up residence among us. We saw his glory – the glory of the one and only, full of grace and truth, who came from the Father. </text> </item> <results>1</results> </bible>"; 
NSString *title = [data componentsSeparatedByString:@"<title>"][1]; 
title=[title componentsSeparatedByString:@"</title>"][0]; 
NSLog(@"%@",title); 

NSString *text = [data componentsSeparatedByString:@"<text>"][1]; 
text=[text componentsSeparatedByString:@"</text>"][0]; 
NSLog(@"%@",text); 

// now assign them to textViews 
titleTextView.text=title; 
textTextView.text=text; 
+0

XML 파일에서 지정된 두 요소를 구문 분석하여 UITextView로 변환하는 방법에 대해 더 살펴 보겠습니다. – iPwnTech

1

https://github.com/nicklockwood/XMLDictionary

을 구문 분석하는 것은 매우 쉽다 xml 및 귀하의 tableView 채우기 위해 데이터를 사용

NSDictionary * baseDic = [NSDictionary dictionaryWithXMLData : [NSData dataWithContentsOfFile : filePath]];

관련 문제