如何通过 nsXml 解析器进行解析

发布于 2024-08-25 01:23:30 字数 524 浏览 4 评论 0原文

我对 iphone 开发非常陌生,我被要求使用 nsxml 解析器从 google api 解析 xml。我已经解析了另一个包含 xml 的 url,但我无法解析 google 的,因为它使用 id 来存储数据而不是内部标记。即

<forecast_information>
    <city data="Anaheim, CA"/>
    <postal_code data="anaheim,ca"/>
    <latitude_e6 data=""/>
    <longitude_e6 data=""/>
    <forecast_date data="2010-03-11"/>
    <current_date_time data="2010-03-12 07:06:32 +0000"/>
    <unit_system data="US"/>
</forecast_information>

有人可以帮助我如何解析标签内的属性。

i am very new to iphone Development and i am asked to use nsxml parser to parse xml from a google api. i have parsed another url which has xml but i am not able to parse google's because it is using id's to store data rather than inside tag. i.e.

<forecast_information>
    <city data="Anaheim, CA"/>
    <postal_code data="anaheim,ca"/>
    <latitude_e6 data=""/>
    <longitude_e6 data=""/>
    <forecast_date data="2010-03-11"/>
    <current_date_time data="2010-03-12 07:06:32 +0000"/>
    <unit_system data="US"/>
</forecast_information>

Can somebody help me that how can i parse the attribute inside the tag.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

粉红×色少女 2024-09-01 01:23:30

NSXMLNode 的名称和值由方法 名称stringValue 。对于属性节点,这些是属性名称和值。

NSXMLElement 的属性由方法 属性,或者可以使用方法 attributeForName:

NSXMLElement *forecast_information;

for( NSXMLElement *el in [forecast_information children] ) {
    NSString *name = [el name];
    NSString *value = @"";
    if ([el attributeForName: @"data"]) {
      value = [[el attributeForName: @"data"] stringValue];
    }
}

The name and value of a NSXMLNode are given by methods name and stringValue respectively. For an attribute node, these are the attibute name and value.

The attributes of a NSXMLElement are given by method attributes, or a particular attribute can be accessed by name with method attributeForName:.

NSXMLElement *forecast_information;

for( NSXMLElement *el in [forecast_information children] ) {
    NSString *name = [el name];
    NSString *value = @"";
    if ([el attributeForName: @"data"]) {
      value = [[el attributeForName: @"data"] stringValue];
    }
}
多情癖 2024-09-01 01:23:30

有人可以帮助我如何解析标签内的属性[使用 NSXMLParser]。

在解析器委托中,实现 parser:didStartElement:namespaceURI:qualifiedName:attributes: 方法。这些属性将位于解析器在最后一个参数中为您提供的字典中。

Can somebody help me that how can i parse the attribute inside the tag [using NSXMLParser].

In your parser delegate, implement the parser:didStartElement:namespaceURI:qualifiedName:attributes: method. The attributes will be in the dictionary that the parser gives you in that last argument.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文