Ios 将web站点中的XML文件解析为UITextView
我正在为iOS开发一个每日圣经引用应用程序,我想知道如何解析在线托管的Ios 将web站点中的XML文件解析为UITextView,ios,xml,xcode,Ios,Xml,Xcode,我正在为iOS开发一个每日圣经引用应用程序,我想知道如何解析在线托管的XML数据,以便在我的应用程序中显示在UITextView中 <bible> <title>John 1:14</title> <item> <bookname>John</bookname> <chapter>1</chapter> <verse>14</verse> <text> Now th
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>
约翰福音1:14
约翰
1.
14
这道成了肉身,住在我们中间。我们看到了他的荣耀——来自天父的独一的荣耀,充满了恩典和真理。
1.
我正在考虑在一个
UITextView
中解析
,在另一个UITextView
中解析
。有人能帮忙吗?使用苹果的NSXMLParser
是可行的选择吗 如果结果数始终为1,则可以拆分字符串以获得所需字段
例如,对于xml字符串,代码
NSString*data=@“约翰福音1:14约翰福音14现在道成了肉身,在我们中间居住。我们看到了他的荣耀——那从父而来、充满恩典和真理的独一者的荣耀;
NSString*title=[数据组件由字符串分隔:@”“][1];
title=[title componentsSeparatedByString:@”“][0];
NSLog(@“%@”,标题);
NSString*text=[数据组件由字符串分隔:@”“][1];
text=[text componentsSeparatedByString:@”“][0];
NSLog(@“%@”,文本);
//现在将它们分配给文本视图
titleTextView.text=标题;
text=text;
我通常使用此库解析xml
解析xml并使用数据填充tableView非常容易
NSDictionary*baseDic=[NSDictionary Dictionary WithXmlData:[NSData dataWithContentsOfFile:filePath]] 更多了解如何将XML文件中的两个指定元素解析为UITextView,以及如何执行。这可能会有所帮助:
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;