获取XML值

时间:2015-08-12 10:28:36

标签: ios objective-c xml-parsing

我有一个我要解析它的xml,我成功完成了这个但我对这个xml的结构有疑问。

<BIBLEBOOK bnumber="1" bname="Genesis" bsname="Gen">
    <CHAPTER cnumber="1">
      <VERS vnumber="1">At the first God made the heaven and the earth.</VERS>
      <VERS vnumber="2">And the earth was waste and without form; and it was dark on the face of the deep: and the Spirit of God was moving on the face of the waters.</VERS>

我如何获得bname的值?

这是我解析xml:

的方法
 NSString *xmlString = [[NSBundle mainBundle] pathForResource:@"basic_english" ofType:@"xml"];
    NSData *xmlData = [NSData dataWithContentsOfFile:xmlString];

    NSString* dataStr  = [[NSString alloc] initWithData:xmlData encoding:NSUTF8StringEncoding];
    NSDictionary *xmlDoc = [NSDictionary dictionaryWithXMLString:dataStr];

1 个答案:

答案 0 :(得分:0)

试试这个。希望它会对你有所帮助。

NSString *bname = [xmlDoc valueForKey:@"_bname"];