在目标C中的两个空XML元素之间解析文本 [英] Parsing Text Between Two Empty XML Elements in Objective C

查看:66
本文介绍了在目标C中的两个空XML元素之间解析文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经知道如何解析包含内容的XML元素(在Objective C中为<this> Content </this>,但是我目前正在使用一个Web服务,该服务返回我一直在网上寻找的两个封闭元素之间的内容(<begin-paragraph/> The content I need <end-paragraph/>)关于任何其他这样做的示例,但我什么也找不到.如果有人知道如何在两个空元素之间阅读并愿意共享,我将非常感激.

I already know how to parse XML Elements that contain content (<this> Content </this> in Objective C but I am currently using a web service that returns the content I need in between two closed elements (<begin-paragraph/> The content I need <end-paragraph/>) I have been looking online for any examples of anyone else doing this, but I could not find anything. If anyone knows how to read between the two empty elements and would care to share, I would appreciate that very much.

推荐答案

我不得不说我认为这是对XML的滥用.

I have to say I regard that as an abuse of XML.

但是我已经检查过,可悲的是它的格式正确,因此NSXMLParser(我认为这是您正在使用的)应该能够应付它.

But I've checked and sadly it is well formed so NSXMLParser (which I assume is what you are using) should be able to cope with it.

您基本上需要通过处理

You basically need to check which element you are in by handling the start element and end element events in your NSXMLParserDelegate. Then after receiving the –parser:didEndElement:namespaceURI:qualifiedName: message for begin-paragraph grab all the text you receive in -parser:foundCharacters: until you receive –parser:didStartElement:namespaceURI:qualifiedName:attributes: for end-paragraph

这篇关于在目标C中的两个空XML元素之间解析文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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