gpt4 book ai didi

ios - 从网站解析 XML 文件到 UITextView

转载 作者:行者123 更新时间:2023-11-28 22:16:04 25 4
gpt4 key购买 nike

我正在为 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>

我正在考虑解析 <title>在一个UITextView<text>在另一个UITextView .有人能帮忙吗?正在使用 Apple 的 NSXMLParser一个可行的选择?

最佳答案

如果结果数总是1,那么您可以拆分字符串以获得所需的字段。

例如,对于您的 xml 字符串,

代码

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;

关于ios - 从网站解析 XML 文件到 UITextView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21642653/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com