0
votes

I have been trying to parse an XML file and all is going well except for one thing.

this is what my XML looks like:

<portfolio>
    <item>
        <image url="http://www.google.com" />
        <title>my first title here.</title>
        <desc>my first description here...</desc>
        <date>15/07/2010</date>
        <skills>skills 1, skills 2, skills 3</skills>
    </item>
</portfolio>

I have been parsing: title, desc, date, and skills perfectly. The only issue I am having is parsing the image url. I am using this simple parser: https://github.com/robertmryan/Simple-XML-Parser

Anyway this is how I am setting up the element names to parse:

parser.elementNames = @[@"image", @"title", @"desc", @"date", @"skills"];

Anyway what do I feed into the element name for the image url based upon the XML snippet I gave above?

Thanks!

Edit: I logged the dictionary it returns after trying the following 3 bits of code:

parser.attributeNames = @[@"image url"];
parser.attributeNames = @[@"image"];
parser.attributeNames = @[@"url"];

Each one of those (after being parsed), returns a dictionary which I logged as this:

dict keys: (
    title,
    skills,
    desc,
    date
)

So something is not working right.

1

1 Answers

1
votes

The image element has a url attribute so you need to specify that you want the attribute to be parsed out too. Do this by setting the value of the attributeNames property on your parser.

This parser is really basic though so it has some limitations. Most important for you is that attributeNames is only used on the 'main' element (specified with rowElementName) so to do what you want to do you will need to edit the parser class to change that.