繁体   English   中英

解析Soap响应时出现问题(iphone / touchxml)

[英]Problem parsing a soap response (iphone / touchxml)

我制作了一个Web服务,它可以工作,问题出在Web服务响应上。 我有这个xml(并且我想用touchxml解析),问题在于touchxml,它发现两个xml,一个在另一个内,它使崩溃。 这是我的问题,我如何解析此xml? 我怎么能删除所有的东西,如soap-env,xmlns ....

<?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);
....
}

我写了这个,虽然不是很优雅,但是可以用。

 NSRange in = [tmpTheXml rangeOfString:@"<return xsi:type=\"xsd:string\">"];
 NSRange fi = [tmpTheXml rangeOfString:@"</return>"];
 int inic = in.location + in.length;
 NSRange tmprange = {inic,fi.location - inic} ;
 tmpTheXml = [tmpTheXml substringWithRange:tmprange];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM