使用 TouchXML 解析子节点
我正在使用 TouchXML 来解析我的 RSS。 新的 XML
<channel>
<item>
<title> </title>
<social>
<views>
<total_views>2</total_views>
</views>
<reviews>
<average_rating>2</average_rating>
</reviews>
</social>
</item>
</channel>
我目前正在解析 XML 并将其与 initWithData
一起传递到我的文章标题的详细视图,如下所示:
[rssData objectForKey: @"title" ];
But how do I show the value of stars it速率的子节点和速率是来自社交的子节点吗?
我已经尝试过: [rssData objectForKey: @"social/rate/stars" ];
但它不起作用。请告诉我怎么做。
I'm using TouchXML to parse my RSS.
The new XML
<channel>
<item>
<title> </title>
<social>
<views>
<total_views>2</total_views>
</views>
<reviews>
<average_rating>2</average_rating>
</reviews>
</social>
</item>
</channel>
I currently parsing the XML and passing it with initWithData
to my detail view for the title of the article like this:
[rssData objectForKey: @"title" ];
But how do I show the value of stars its a subnode of rate and rate is a subnode from social?
I have tried this: [rssData objectForKey: @"social/rate/stars" ];
But it won't work. Please tell me how.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我基于原始答案的整个前提似乎是错误的。如果您使用以下代码片段
来生成代码,则
social
元素的子元素将存储为字符串值,并且提取它们的任何合理方法都会丢失。我建议您存储节点而不是创建字典。这是提取评级的示例,The entire premise that I based my original answers seem to be wrong. If you've used the following snippet,
to generate your code than children of
social
element are stored as a string value and any reasonable means to extract them are lost. I would suggest that you store the nodes rather than go about creating the dictionary. Here's the example of extracting the rating,尝试这个,你需要传递 readNode 值,如“channle”,它将返回数组,包括子子节点
try this , you need to pass readNode value like "channle", and it will return array, including child subnode