0

我一直在尝试解析一个 XML 文件,除了一件事之外,一切都很顺利。

这就是我的 XML 的样子:

<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>

我一直在完美解析:title、desc、date和skill。我遇到的唯一问题是解析图像网址。我正在使用这个简单的解析器:https ://github.com/robertmryan/Simple-XML-Parser

无论如何,这就是我设置要解析的元素名称的方式:

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

无论如何,根据我上面给出的 XML 片段,我应该为图像 url 的元素名称提供什么?

谢谢!

编辑:我在尝试以下 3 位代码后记录了它返回的字典:

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

其中的每一个(在被解析之后)都会返回一个字典,我将其记录为:

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

所以有些事情不正常。

4

1 回答 1

1

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.

于 2013-08-18T19:28:06.140 回答