使用GDataXML在iPhone上解析XML

时间:2011-07-16 02:17:58

标签: iphone xml gdataxml

呃,我有一段时间从Exchange Web Services解析xml。我想获得ItemID Id = xyz属性(AAATAG ...)。这是XML:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Header><t:ServerVersionInfo xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" MajorVersion="8" MinorVersion="3" MajorBuildNumber="137" MinorBuildNumber="0"/></soap:Header><soap:Body><m:FindItemResponse xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages"><m:ResponseMessages><m:FindItemResponseMessage ResponseClass="Success"><m:ResponseCode>NoError</m:ResponseCode><m:RootFolder TotalItemsInView="1" IncludesLastItemInRange="true"><t:Items><t:CalendarItem><t:ItemId Id="AAATAGNvb3Blcm1qQG11b2hpby5lZHUARgAAAAAA+Q4xQgA/2kCus7bZbZddngcA8vxBsULRa0S+uFR566ChHwAAAB4BwgAABgoCL+IgvEaj+O0Bl9BG2AAQEOyJMwAA" ChangeKey="DwAAABYAAAAGCgIv4iC8RqP47QGX0EbYABARELYs"/><t:Organizer><t:Mailbox><t:Name>Cooper, Micah</t:Name></t:Mailbox></t:Organizer></t:CalendarItem></t:Items></m:RootFolder></m:FindItemResponseMessage></m:ResponseMessages></m:FindItemResponse></soap:Body></soap:Envelope>

我正在使用GDataXML,这是我的代码:

- (void)parseFeed:(GDataXMLElement *)doc entries:(NSMutableArray *)entries {    
NSLog(@"%@", doc);


NSDictionary *namespaceMappings = [NSDictionary dictionaryWithObjectsAndKeys:@"http://schemas.microsoft.com/exchange/services/2006/messages", @"messages",
                                   @"http://schemas.microsoft.com/exchange/services/2006/types",@"types", nil];


NSArray *items = [doc nodesForXPath:@"//types:CalendarItem" namespaces:namespaceMappings error:nil];    
for (GDataXMLElement *item in items) {
    NSLog(@"Item: %@", item.stringValue);
    NSString *itemID = [[item attributeForName:@"ItemId Id"] stringValue];
    NSLog(@"itemID: %@", itemID);
}

}

我没有提取项ID - 事实上,它看起来好像是在XML中的随机位置进行解析。谁能指出我正确的方向?谢谢!

0 个答案:

没有答案