Parsing Text Between Two Empty XML Elements in Obj

2019-08-29 12:03发布

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.

2条回答
聊天终结者
2楼-- · 2019-08-29 12:21

I don't know what the DOM conformance on the iPhone is like, but the general procedure would be:

  1. Navigate to <begin-paragraph /> in your DOM.
  2. Get the next sibling of that node. That is the content you need. (Node::nextSibling property)
  3. If there are other elements in there that you want, keep collecting them by the same method, until you reach <end-paragraph />
查看更多
等我变得足够好
3楼-- · 2019-08-29 12:22

I have to say I regard that as an abuse of 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.

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

查看更多
登录 后发表回答