[英]Parsing Text Between Two Empty XML Elements in Objective C
我已经知道如何解析包含内容的XML元素(在Objective C中为<this> Content </this>
,但是我目前正在使用一个Web服务,该服务返回两个封闭元素之间的所需内容( <begin-paragraph/> The content I need <end-paragraph/>
)我一直在网上寻找任何其他这样做的例子,但是我什么也找不到。如果有人知道如何在两个空白元素之间进行阅读并愿意分享,我会非常感谢。
I have to say I regard that as an abuse of XML. 我不得不说我认为这是对XML的滥用。
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. 但是我已经检查过,令人遗憾的是它的格式正确,因此NSXMLParser(我假设您正在使用的)应该能够应对。
You basically need to check which element you are in by handling the start element and end element events in your NSXMLParserDelegate . 基本上,您需要通过处理NSXMLParserDelegate中的start元素和end元素事件来检查您所在的元素。 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
然后,在收到
–parser:didEndElement:namespaceURI:qualifiedName:
消息的begin-paragraph
抓取您在-parser:foundCharacters:
收到的所有文本,直到收到–parser:didStartElement:namespaceURI:qualifiedName:attributes:
作为end-paragraph
I don't know what the DOM conformance on the iPhone is like, but the general procedure would be: 我不知道iPhone上的DOM一致性如何,但是一般过程如下:
<begin-paragraph />
in your DOM. <begin-paragraph />
。 <end-paragraph />
<end-paragraph />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.