0

我正在使用 TouchXML 解析 WSDL 文件,而且我是新手,有一个像这样的 NSString

NSString *str = @"<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><soap:Body><ns1:createSessionResponse xmlns:ns1=\"http://soap.user/\"><ns1:out>9E0B34E6DFF7BF89</ns1:out></ns1:createSessionResponse></soap:Body></soap:Envelope>";

如何在“ns:out”中获取字符串9E0B34E6DFF7BF89

4

1 回答 1

0

试试这个 :

NSString *str = @"<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><soap:Body><ns1:createSessionResponse xmlns:ns1=\"http://soap.user/\"><ns1:out>9E0B34E6DFF7BF89</ns1:out></ns1:createSessionResponse></soap:Body></soap:Envelope>";
NSRange rr2 = [str rangeOfString:@"<ns1:out>"];
NSRange rr3 = [str rangeOfString:@"</ns1:out>"];
int lengt = rr3.location - rr2.location - rr2.length;
int location = rr2.location + rr2.length;
NSRange aa;
aa.location = location;
aa.length = lengt;
str = [str substringWithRange:aa];
NSLog(@"%@",str);  // 9E0B34E6DFF7BF89
于 2012-05-30T03:59:21.290 回答