• Gdataxml 例子


    <Party>

      <Player>

        <Name>Butch</Name>

        <Level>1</Level>

        <Class>Fighter</Class>

      </Player>

      <Player>

        <Name>Shadow</Name>

        <Level>2</Level>

        <Class>Rogue</Class>

      </Player>

      <Player>

        <Name>Crak</Name>

        <Level>3</Level>

        <Class>Wizard</Class>

      </Player>

    </Party>

    NSError *error;

    NSData* xmlData= [xmlString dataUsingEncoding: NSASCIIStringEncoding];

    GDataXMLDocument *doc = [[GDataXMLDocument alloc] initWithData:xmlData options:0 error:&error];

    if (doc == nil) { return nil; }

    //NSArray *partyMembers = [doc.rootElement elementsForName:@"Player"];

     NSArray *partyMembers = [doc nodesForXPath:@"//Party/Player" error:nil];

    for (GDataXMLElement *partyMember in partyMembers) {

    // Let's fill these in!

    NSString *name;

    int level;

    // Name

    NSArray *names = [partyMember elementsForName:@"Name"];

    if (names.count > 0) {

    GDataXMLElement *firstName = (GDataXMLElement *) [names objectAtIndex:0];

    name = firstName.stringValue;

    } else continue;

    // Level

    NSArray *levels = [partyMember elementsForName:@"Level"];

    if (levels.count > 0) {

    GDataXMLElement *firstLevel = (GDataXMLElement *) [levels objectAtIndex:0];

    level = firstLevel.stringValue.intValue;

    } else continue;

    // Class

    NSArray *classes = [partyMember elementsForName:@"Class"];

    if (classes.count > 0) {

    GDataXMLElement *firstClass = (GDataXMLElement *) [classes objectAtIndex:0];

    if ([firstClass.stringValue caseInsensitiveCompare:@"Fighter"] == NSOrderedSame)

    {

    } else if ([firstClass.stringValue caseInsensitiveCompare:@"Rogue"] == NSOrderedSame) {

    } else if ([firstClass.stringValue caseInsensitiveCompare:@"Wizard"] == NSOrderedSame) {

    } else {

    continue;

    }            

    } else continue;

    }

    [doc release];

    [xmlData release];

  • 相关阅读:
    作业 第四 张垚
    软件测试课堂练习 张垚
    增删改查
    计算器 作业
    activity 张垚
    第四作业 张垚
    第六周作业
    jsp第四周作业
    jsp求1-100之间的素数和
    JSP第一次测试
  • 原文地址:https://www.cnblogs.com/zzxap/p/2175620.html
Copyright © 2020-2023  润新知