0

この問題で私を助けてください、私はこの問題の下で先週打った

でサーバーから XML 応答を取得しconnectionDidFinishLoading:ます。属性値を取得するために XML 解析メソッドのメソッドを呼び出しましたが、パーサー メソッドを呼び出して値を取得しません。

これは、サーバーから取得している XML 構造です。xml でステータス属性の値を取得しようとしましたが、取得できません。

<?xml version="1.0"?>
<response action="registration">
   <element>
      <properties name="username">test1@test.com</properties>
      <properties name="ticket"></properties>
      <properties name="chatNickName">test</properties>
      <properties name="vendorid"></properties>
      <properties name="currencyid">USD</properties>
      <properties name="status">0</properties>
      <properties name="errdesc"></properties>
   </element>
</response>



-(void)callWs:(id)parentView:(NSString *)soapMessage

{

    if ([parentView isKindOfClass:[ViewController class]])
    {
        NSLog(@"wodObj");
        viewobj = (ViewController *)parentView;
    }

    responseText = [[NSString alloc] init];

    NSURL *url = [NSURL URLWithString:[WSAddress getWsAddress]];
    NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
    NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];

    [theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
    [theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
    [theRequest setHTTPMethod:@"POST"];
    [theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];

  NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];

    if( theConnection )
    {
        receivedData = [NSMutableData data];
    }
    else
    {
        NSLog(@"theConnection is NULL");
    }

}


-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response

{
    [receivedData setLength:0];

 }
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data

{

 [receivedData appendData:data];

  }

-(void)connection:(NSURLConnection *)connectiondidFailWithError:(NSError *)error
{
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    NSString *theXML = [[NSString alloc] initWithBytes: [receivedData mutableBytes] length:[receivedData length] encoding:NSUTF8StringEncoding];
    NSLog(@"theXML ::%@",theXML);
    if (xmlParser) {
        //[xmlParser release];
    }
    xmlParser = [[NSXMLParser alloc] initWithData:receivedData];
    [xmlParser setDelegate:self];
    [xmlParser setShouldResolveExternalEntities:YES];
    [xmlParser parse];
    if (viewobj != nil) {
        viewobj.wodTextview.text = self.responseText;
        NSLog(@"wod_meaning %@ ",wod_meaning);
        viewobj.Wod_meaning.text =self.wod_meaning;
        viewobj.linkurl =self.link;

    }
}

NSString *label;
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{

    if ([[attributeDict objectForKey: @"name"] isEqualToString: @"status"]) {
        NSLog(@"found category with name Local");
    }

    if ([elementName isEqualToString:@"properties"]) {
        label = @"properties";
    }

}

- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{
    if ([label isEqualToString:@"name"]) {
        label = @"";
        self.responseText = @"\" ";
        self.responseText = [self.responseText stringByAppendingString:string];
        self.responseText = [self.responseText stringByAppendingString:@" \""];
        NSLog(@" self._wod %@", self.responseText);

    }

    if ([label isEqualToString:@"properties"]) {
        label = @"";
        self.responseText = @"\" ";
        self.responseText = [self.responseText stringByAppendingString:string];
        self.responseText = [self.responseText stringByAppendingString:@" \""];
        NSLog(@" self._wod %@", self.responseText);

    }


}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{
}

これは、サーバーに接続し、その後応答を取得してデリゲート メソッドを解析し、属性値を取得するための私のコードです。

4

0 に答える 0