gpt4 book ai didi

iphone - 使用 touchXML 解析 SOAP 响应 - 一个问题

转载 作者:行者123 更新时间:2023-12-03 20:10:41 28 4
gpt4 key购买 nike

我还有 obj-c 的另一个问题:我正在尝试解析此 XML:

情况如下:

<?xml version="1.0" encoding="utf-8"?>
<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:Body>
<GetMyDashboardResponse xmlns="http://tempuri.org/">
<GetMyDashboardResult>
<MyDashboard>
<Profile>Speed Seeker</Profile>
<UserID>6</UserID>
<VenueName>Prasowa</VenueName>
<FriendsCount>10</FriendsCount>
<FollowingCount>11</FollowingCount>
<FollowersCount>12</FollowersCount>
<StatusMessage>aaa</StatusMessage>
<StatusDate>2010-08-04T11:38:09.733</StatusDate>
<CheckedInTimeStamp>2010-07-30T13:48:24</CheckedInTimeStamp>
</MyDashboard>
</GetMyDashboardResult>
</GetMyDashboardResponse>
</soap:Body>
</soap:Envelope>

这就是我试图实现它的方法:

NSMutableArray *res = [[NSMutableArray alloc] init];

CXMLDocument *doc = [[[CXMLDocument alloc] initWithData:XMLData options:0 error:nil] autorelease];

NSArray *nodes = NULL;
nodes = [doc nodesForXPath:@"//MyDashboard" error:nil];

for (CXMLElement *node in nodes)
{
NSMutableDictionary *item = [[NSMutableDictionary alloc] init];
int counter;
for(counter = 0; counter < [node childCount]; counter++)
{
[item setObject:[[node childAtIndex:counter] stringValue] forKey:[[node childAtIndex:counter] name]];
}
[item setObject:[[node elementsForName:@"Profile"] stringValue] forKey:@"profileName"]; // <------ this magical arrow is pointing to the area of interest
NSLog(@"petla");
[res addObject:item];
[item release];
}

NSLog(@"%@", res);
[res release];

`

感谢您的帮助。

最佳答案

[node elementsForName] 将返回 NSArray,因此您绝对不能在其上使用 stringValue 。创建临时 NSArray,为其设置 elementsForName,检查其对象计数是否 > 0,获取 objectAtIndex:0 就可以了!

关于iphone - 使用 touchXML 解析 SOAP 响应 - 一个问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3404515/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com