Finding parent node of parsed XML in Objective-C
I'm parsing through a bunch of XML and I'm trying to fi开发者_JAVA百科nd if a node is inside / parent of another node before I process it. Is there a way of knowing what the parent of a niode is?
Record the parent node yourself. You're using an event-based parser. It very deliberately keeps track of nothing except what is necessary to ensure the document is well-formed. If you need to know the parent node, record each node in a stack in didStartElement and then pop off the node in didEndElement.
精彩评论