Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 将web站点中的XML文件解析为UITextView_Ios_Xml_Xcode - Fatal编程技术网

Ios 将web站点中的XML文件解析为UITextView

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

我正在为iOS开发一个每日圣经引用应用程序,我想知道如何解析在线托管的
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;