0

私が作成しているiOSプログラムで、SOAPを使用したコースのリストを要求しています。これは返信形式です

<ListCoursesResponse>
          <statusMessage xmlns="xxx">string</statusMessage>
          <courseID xmlns="xxx">string</courseID>
          <courseTitle xmlns="xxx">string</courseTitle>
        </ListCoursesResponse>
        <ListCoursesResponse>
          <statusMessage xmlns="xxx">string</statusMessage>
          <courseID xmlns="xxx">string</courseID>
          <courseTitle xmlns="xxx">string</courseTitle>
</ListCoursesResponse>

私は、それぞれの配列をステップスルーしてコースIDの間にあるものを抽出するのではなく、それぞれの個別のコースを配列の要素として抽出するという方針に沿って何かを使用しています。ただし、複数を抽出する方法がわかりません。返却すると、最初のコースしか表示されないためです。私がこれを悪い方法で説明した場合は、私がよりよく説明できるように教えてください。

私の質問は、XML応答で返されるコースの大規模なリスト(200以上)にアプローチするための最良の方法は何ですか?

編集:私が使用しているコードのスニペット。1つのIDのみを返します。

NSString *tag1Open = @"<ListCoursesResponse>";
    NSString *tag1Close = @"</ListCoursesResponse>";
    NSString *courseIDOpen = @"<courseID xmlns=\"http://drm.mediuscorp.com/\">";
    NSString *courseIDClose = @"</courseID>";
    result = @"";
    NSArray *XMLarray1 = [XMLResult componentsSeparatedByString:tag1Open];
    if ([XMLarray1 count] > 1) {

        for (int i = 0; i < [XMLarray1 count]; i++) {
            NSString *courseIDString = [[[XMLarray1 objectAtIndex:1]componentsSeparatedByString:tag1Close]objectAtIndex:0];

            NSArray *courseID = [XMLResult componentsSeparatedByString:courseIDOpen];

            if ([courseID count] > 1) {

                for (int i = 0; i < [courseID count]; i++) {
                    courseIDString = [[[courseID objectAtIndex:1]componentsSeparatedByString:courseIDClose]objectAtIndex:0];

                }

            }
        NSLog(@"Course ID: %@",courseIDString);


        }
        [persArray addObject:result];
        for (int i = 0; i < [persArray count]; i++) {
            NSLog(@"%@",[persArray objectAtIndex:i]);
        }
    }
4

1 に答える 1

1

Rather than try to parse the SOAP XML response response yourself using NSString methods, you would be much better off using an XML Parser to handle this task. iOS has a built-in XML Parser called NSXMLParser that is available to you. (There are also numerous third-party XML Parser components available, of both SAX and DOM varieties)

Here is a tutorial that gives an example of using NSXMLParser.

于 2012-08-13T21:46:37.953 に答える