I need help in parsing XML
<Grandfather>
<Son name="1">
<Grandson name="1" />
</Son>
<Son name="2">
<Grandson name="1" />
</Son>
<Son name="3">
<Grandson name="1" />
<Grandson name="2" />
<Grandson name="3" />
</Son>
</Grandfather>
Can any body tell me how to convert this XML into dictionary
of the format
key(son) value(NSArray of grandsons)
Thanks in advance
Replies
Look into NSXMLParser, it's quite easy to use.
I tried but with no luck
More help is required as I am new to iPhone application development
Event-Driven XML Programming Guide for Cocoa: Introduction to Event-Driven XML Programming Guide for Cocoa
<a href="http://www.kelvinkaodev.com" target="_blank">http://www.kelvinkaodev.com</a>
XML to NSDictionary Converter bcaccinolo's blog
The code is on Github.
Cheers,
https://github.com/Insert-Witty-Name/XML-to-NSDictionary
You simply do:
You get:
I used the XMLReader class to get a NSDictionary and everything works fine. But i can't to get the values of the atributes of my productData element.
Specifically i have the following NSDictionary:
{
response = {
products = {
productsData = (
{
alias = "Product 1";
id = 01;
price = "10";
},
{
alias = "Product 2";
id = 02;
price = "20";
},
{
alias = "Product 3";
id = 03;
price = "30";
}
);
};
};
}
I used this code to create de NSDictionary:
NSDictionary *dictionary = [XMLReader dictionaryForXMLData:responseData error:&parseError];
and responseData contains:
<application><products>
<productData>
<id>01</id>
<price>10</price>
<alias>Product 1</alias>
</productData>
<productData>
<id>02</id>
<price>20</price>
<alias>Product 2</alias>
</productData>
<productData>
<id>02</id>
<price>20</price>
<alias>Product 3</alias>
</productData>
</products>
</application>
Then, i don't know how get the values of each productData like id, price and alias...
Anybody know how do it??
Thanks and please forgive my bad english