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

发布于 2024-09-13 00:06:54 字数 2153 浏览 5 评论 0原文

我还有 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];

`

感谢您的帮助。

i've another problem with obj-c:
i'm trying to parse this XML :

here's the case:

<?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>

and here's how i'm trying to accomplish it:

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];

`

thanks for any help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

十六岁半 2024-09-20 00:06:54

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

[node elementsForName] will return NSArray, so you definitely can't use stringValue on that. Create temporary NSArray, set elementsForName to it, check if its object count > 0, take objectAtIndex:0 and you're good to go!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文