iPhone:使用属性解析XML文件 [英] iPhone : Parse XML file with attribute

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

问题描述

我想解析XML文件。我能够解析简单的XML文件。但是没有复杂的XML文件

i want to parse the XML file. i am enable to parse simple XML file. but there are little complex XML file

<?xml version="1.0" encoding="utf-8"?>
<Level>
<p id='327'>
   <Item>
      <Id>5877</Id>
      <Type>0</Type>
      <Icon>---</Icon>
      <Title>Btn1Item1</Title>
   </Item>
   <Item>
      <Id>5925</Id>
      <Type>0</Type>
      <Icon>---</Icon>
      <Title>Btn1Item4</Title>
   </Item>
</p>
</Level>

这里我想获得< p> tag(我的意思是我想得到属性id的值为327)
请建议

Here i want to get the value of <p> tag (i mean i want to get the value of attribute id which is 327) Please suggest

推荐答案

你可以使用下面的代码在XML解析方法中找到你的id值,

You can use below code to find your "id" value in XML parsing method,

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

    if([elementName isEqualToString:@"p"])
    {

        int idValue = [[attributeDict objectForKey:@"id"] intValue];

        NSLog(@"Reading id value :%d", idValue);
    }

}

这篇关于iPhone:使用属性解析XML文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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