2013-08-05 162 views
0

我試圖解析與AFXMLRequestOperation一個XML卻發現「C」的字符串時,停止解析,我不知道究竟是如何解析的繼承人字符串的這個PICE代碼:錯誤解析XML編碼目標C

AFXMLRequestOperation * op = [AFXMLRequestOperation XMLParserRequestOperationWithRequest:req success:^(NSURLRequest *request, NSHTTPURLResponse *response, NSXMLParser *XMLParser) 
{ 
    NSLog(@"XML document %@", XMLParser); 
    NSLog(@"response %@",response); 

    XMLParser.delegate = self; 
    [XMLParser parse]; 

}failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, NSXMLParser *XMLParser) { 
    NSLog(@"response %@",response); 
    NSLog(@"Error %@", error); 
}]; 


- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string 
{  
    NSString *correctString = [NSString stringWithCString:[string cStringUsingEncoding:NSISOLatin1StringEncoding] encoding:NSUTF8StringEncoding]; 
    NSLog(@"string %@",correctString); 
} 

這裏是XML:

<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsa="http://www.w3.org/2005/08/addressing"><env:Header><wsa:MessageID>urn:E350F180FDEF11E2BF9C23C51C52395C</wsa:MessageID><wsa:ReplyTo><wsa:Address>http://www.w3.org/2005/08/addressing/anonymous</wsa:Address><wsa:ReferenceParameters><instra:tracking.ecid xmlns:instra="http://xmlns.oracle.com/sca/tracking/1.0">66a9395e96ada9e8:-78e4245e:1401282173b:-8000-0000000000210667</instra:tracking.ecid></wsa:ReferenceParameters></wsa:ReplyTo><wsa:FaultTo><wsa:Address>http://www.w3.org/2005/08/addressing/anonymous</wsa:Address><wsa:ReferenceParameters><instra:tracking.ecid xmlns:instra="http://xmlns.oracle.com/sca/tracking/1.0">66a9395e96ada9e8:-78e4245e:1401282173b:-8000-0000000000210667</instra:tracking.ecid></wsa:ReferenceParameters></wsa:FaultTo></env:Header><env:Body><TransactionResponse xmlns:aia="http://www.oracle.com/XSL/Transform/java/oracle.apps.aia.core.xpath.AIAFunctions" xmlns:ns0="http://www.site.com.br/" xmlns="http://www.site.com.br/"><ns0:Acquirer>ECOMMERCE</ns0:Acquirer><ns0:TransactionId>00</ns0:TransactionId><ns0:Complement>192071</ns0:Complement><ns0:AdditionalComplement>123456</ns0:AdditionalComplement><ns0:ResponseCode>00</ns0:ResponseCode><ns0:ResponseMessage>Transação Autorizada</ns0:ResponseMessage><ns0:TransactionStatus>PAGO</ns0:TransactionStatus><ns0:TransactionDate>2013-08-05T13:55:37.602-03:00</ns0:TransactionDate><ns0:OrderNumber>0000014</ns0:OrderNumber></TransactionResponse></env:Body></env:Envelope> 
+0

可能重複[的NSXMLParser沒有得到所有的標籤,如果標籤有口音(http://stackoverflow.com/questions/14986699/nsxmlparser-dont-get-all-the-tag-if -tag-have-accent) - 簡短的回答:你必須*追加* foundCharacters中的字符串。 –

+0

不工作@MartinR已經嘗試過。 – darkman

+0

'parse'是否返回NO?什麼是'parserError'?爲什麼編碼轉換? –

回答

0

你可以試試這個,這爲我工作。

 
const char *cc= [currentElementValue cStringUsingEncoding:NSISOLatin1StringEncoding]; 
NSString *d_string = [[NSString alloc]initWithCString:cc encoding:NSUTF8StringEncoding];