Jakub
Jakub

Reputation: 13860

NSXMLParser : where store values?

I want to that my app will work with XML file as some kind of pre - initializer. I want to analyse xml file and then draw screens. So for example i have a xml file in struct:

<app>
   <screens>        
    <screen name="myscreen1">
            <font fontsize="32" fontcolor="#000000" fontface="font.ttf"/>

            <button tmpl="bk"/>

            <list area="0px 74px 100% 100%">
                <item tmpl="myitem1" target="myitemelsewhere">
                    <image tmpl="myitem1" img="myimg1.png"/>
                    <text tmpl="myitem1">Test</text>
                </item>
                <item tmpl="myitem2" target="myitemelsewhere">
                    <image tmpl="myitem2" img="myimg2.png"/>
                    <text tmpl="myitem2">Test</text>
                </item>
             </list>
    </screen>
<!--screen 2 the same way -->
</screens>
</app>

I implement NSXMLparser and i can simply read attributes and tags. That's not an issue. My question is. When I get the first element (ex myscreen1) what is the best idea where to put it, and grab all the screen declaration tags and attributes later? NSSet? NSDictionary? NSArray? For example:

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict 
{
    element = [NSMutableString string];

    if([elementName isEqualToString:@"screen"])
    {
        //What should i do here to tell my app to store all attributes? Where to put this?
    }
}

Upvotes: 0

Views: 231

Answers (1)

nevan king
nevan king

Reputation: 113747

You usually have a variable to keep the data which is streaming in and a variable to store the XML tag you are processing. The place that you give above is for setting the XML tag that you're currently processing. Here's a great piece of example code to get you started:

http://weblog.bignerdranch.com/?p=48

Upvotes: 1

Related Questions