获取元素的值而不解析ios中的所有xml文件 [英] Get value of an element without parse all xml file in ios

查看:54
本文介绍了获取元素的值而不解析ios中的所有xml文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有可能,在不使用所有委托 NSXMLParse 方法的情况下获取 xml 文件的特定元素值,我知道在 OS X 中可以通过两个简单的行:

i want know if is possible, to get a specific element value of a xml file without use all delegate NSXMLParse method, i know that in OS X is possible with two simple line:

    NSXMLDocument *xmlDoc = [[NSXMLDocument alloc] initWithData:connection.data options:0 error:nil];

    NSString *time = [[xmlDoc rootElement] stringValueForXPath:@"./Time"];

可以在 iOS 中做同样的事情吗?几行?

is possible do the same thing in iOS? with few line?

谢谢

推荐答案

XPath 也适用于 iOS.这是一个关于使用 libxml2、XPath 和 XML 解析数据的非常棒的教程.

XPath exists for iOS, as well. Here is a really great tutorial on using libxml2, XPath, and XML for parsing data.

爱可口可乐

使用 XPath,您需要传入剪辑查询.对于以下 XML,您的剪辑查询将是//day":

With XPath, you're expected to pass in a clip query. For the following, XML, your clip query would be "//day":

<day>
Monday
</day>
<day>
Tuesday
</day>
...
<day>
Friday
</day> 

这将为您提供一个包含 5 个字典的数组,其中 node_name = day 和 node_content = 星期几.

This will give you an array of 5 dictionaries with node_name = day and node_content = the day of the week.

这篇关于获取元素的值而不解析ios中的所有xml文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆