Re: NSXMLParser question
Re: NSXMLParser question
- Subject: Re: NSXMLParser question
- From: Sherm Pendley <email@hidden>
- Date: Mon, 20 Jun 2005 12:22:30 -0400
On Jun 20, 2005, at 11:39 AM, Jesus De Meyer wrote:
I'm currently stuck with parsing a specific type of xml file.
Imagine the following hierarchy:
<root>
<item>
<item />
<item>
<item />
<item />
</item>
</item>
I know how to parse it, but the problem I'm having is with the
close tags. How do I know if the close tag belongs to an item (in
the case of <item />) or to a group of items (like in <item> ... </
item>)
The traditional way to do it is to use a stack. When you receive an
opening tag, create a new element and push is onto the top of your
stack. XML is strictly hierarchical, so assuming well-formed XML,
whenever you receive a closing tag it will match the top opening tag
on the stack Pop that element off the top of the stack, and the next
item on the stack will be the just-popped item's immediate parent.
sherm--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden