1

呃,我在从 Exchange Web 服务解析 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 中的随机位置进行解析。谁能指出我正确的方向?谢谢!

4

0 回答 0