0
我做了一個web服務,它的工作原理,問題是與web服務響應。 我有這個XML(我想解析touchxml),問題是與touchxml,它發現兩個XML,一個在另一個裏面,它使崩潰。 這是我的問題,我如何解析這個XML?我怎麼可以去除所有的東西,如SOAP-ENV,XMLNS ....解析肥皂響應問題(iphone/touchxml)
<?xml version="1.0" encoding="ISO-8859-1"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body>
<ns1:getCategoriesResponse xmlns:ns1="http://192.168.1.30/wyws/server.php"><return xsi:type="xsd:string">
<?xml version="1.0" encoding="UTF-8"?>
<categories>
<category id="1" desc="Encontrar Códigos " icon="wy">Código </category>
<category id="3" desc="" icon="farm">Far</category>
<category id="5" desc="" icon="gas">Gas</category>
<category id="6" desc="" icon="hos">Hos</category>
<category id="7" desc="" icon="pol">Pol</category>
</categories>
</return></ns1:getCategoriesResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>
這是我如何撥打電話:
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];
[theRequest addValue:@"8bit" forHTTPHeaderField:@"Content-Transfer-Encoding"];
[theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[theRequest addValue: @"getCategories" forHTTPHeaderField:@"SOAPAction"];
[theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody:[soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
webData = [[NSMutableData data] retain];
然後
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSLog(@"DONE. Received Bytes: %d", [webData length]);
NSString *theXML = [[NSString alloc] initWithBytes: [webData mutableBytes] length:[webData length] encoding:NSISOLatin1StringEncoding];
NSLog(theXml);
....
}