我有以下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
发布评论