iPhone 应用程序的 xml paeser
我在服务器上有一个 xml 文件,例如,如下所示:
<breakfast_menu>
<food>
<name>Belgian Waffles</name>
<price>$5.95</price>
<description>two of our famous Belgian Waffles with plenty of real maple syrup</description>
<calories>650</calories>
</food>
<food>
<name>Strawberry Belgian Waffles</name>
<price>$7.95</price>
<description>light Belgian waffles covered with strawberries and whipped cream</description>
<calories>900</calories>
</food>
</breakfast_menu>
我需要 xml 解析器来解析它,并将它们中的每一个输入到一个类中,例如,该类将称为食物(并且有 4 个参数:名称、价格)。 ....)。 最后创建他创建的类的数组。是否有内置的 xml 解析器可以做到这一点?
i have a xml file on a server that look for example like this one:
<breakfast_menu>
<food>
<name>Belgian Waffles</name>
<price>$5.95</price>
<description>two of our famous Belgian Waffles with plenty of real maple syrup</description>
<calories>650</calories>
</food>
<food>
<name>Strawberry Belgian Waffles</name>
<price>$7.95</price>
<description>light Belgian waffles covered with strawberries and whipped cream</description>
<calories>900</calories>
</food>
</breakfast_menu>
i need xml parser that will parse it and enter each one of them to a class that for examle will called food(and have 4 parameters : name,price,.....).
and finally to create an array of the classes that he create.there is built xml parser that do it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
以下是有关该主题的一些来源:
Here are some sources on the topic:
要学习解析 xml,请查看 Brandon 提供的链接。您需要自己创建从 xml 构建类数组的要求。
我给你的建议是不要创建类,只需将数据放入
NSMutableArray
中即可。该数组将包含食物子项的 NSDictionary 对象。For learning to parse xml, look at the links Brandon provided. Your requirement to build an array of classes from xml is something you'll need to create yourself.
A suggestion I have for you is instead of creating classes, just put the data into a
NSMutableArray
. The array will containNSDictionary
objects for food sub-items.