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