具有多个属性的NSXMLParser

编程入门 行业动态 更新时间:2024-10-25 06:21:12
本文介绍了具有多个属性的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

本文发布于:2023-11-22 03:35:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1615822.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   属性   NSXMLParser

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!