具有多个属性的NSXMLParser [英] NSXMLParser with multiple attributes

查看:67
本文介绍了具有多个属性的NSXMLParser的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下XML(正在为iPhone做一个应用程序):

I have the following XML (doing an app for iPhone):

<Row>
<Field name="employee_id_disp">00070431</Field>
<Field name="given_name">John</Field>
<Field name="family_name">Doe</Field>
</Row> ...

如何仅检索其中一个属性的值,例如 John值for attribute name = given_name吗?

How can I retrieve values only for one of the attributes, for example value "John" for attribute name="given_name" ?

感谢答案。

推荐答案

大概,您将使用 NSXMLParser 对此进行解析。

Presumably, you'll be using NSXMLParser to parse this.

这意味着您的 didStartElement:委托回调,您应该检查传递的属性字典以查看其是否具有值为 given_name的键 name 。如果是这样,您将要设置一些标志,以开始记录在 foundCharacters:回调中找到的字符。到达元素字段的 didEndElement:回调后,您将所有字符聚合到一个字符串中,该字符串即为名称。 (很有可能,所有字符都会在一个回调中报告给 foundCharacters:,但这不能保证。)

That means in your didStartElement: delegate callback, you should check the passed attributes dictionary to see if it has a key "name" with a value "given_name". If it does, you'll want to set some flag that you can start recording the characters found in foundCharacters: callback. Once you reach the didEndElement: callback for the element "Field", you'll have aggregated all the characters into a string, and that string is the name. (Most likely, the characters will all come be reported in one callback to foundCharacters:, but that's not guaranteed).

这篇关于具有多个属性的NSXMLParser的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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