如何解析以下XML? [英] How to parse the following XML?

查看:96
本文介绍了如何解析以下XML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<colors>
    <color colorName="Abracadabra" colorNumber="D51-2" rColor="209" gColor="224" bColor="229" colorCollection="Harmony" colorFamily="Shaded" rating="3" surfaces="" colorGroup="Blues" />
    <color colorName="Abyss" colorNumber="B50-1" rColor="233" gColor="247" bColor="249" colorCollection="" colorFamily="Clean" rating="3" surfaces="" colorGroup="Blues" />
<colors>

我从Web服务获取上述XML数据。我没有得到如何解析它。我想要'colorNameArray'包含所有颜色名称,'colorNumberArray'包含所有颜色数字等等所有细节。解析器代表的代码很明显。
谢谢

I am getting the above XML data from web service. I am not getting how to parse it.I would like to have 'colorNameArray' containing all the color names, 'colorNumberArray' containing all the color numbers and so on for all the details. Code for this with parser delegates is appreciable. Thank You

推荐答案

这个链接很好地理解了使用nsxmlparser的xml解析。(示例代码可用)。

This link gives a good understanding for xml parsing using nsxmlparser .(sample code available).

这些值作为属性存在,因此可以从nsxmlparser的didStartElement委托方法的attributeDict获得。

The values are present as the attributes so it can be obtained from attributeDict of didStartElement delegate method of nsxmlparser.

ex:

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{ 

 if([elementName isEqualToString:@"color"])
{
    NSString* colorName = [attributeDict objectForKey:@"colorName"]];

}   
}

All The Best。

All The Best.

这篇关于如何解析以下XML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆