我正在尝试使用 SOAP 解析从我的 WebService 接收到的以下字符串。由于我无法解析从我的 Web 服务接收到的数据(我不知道为什么……请看这里解析 XML使用 Soap Web 服务)我将数据转换为 NSString,然后使用 TOUCHXML 解析字符串
NSString *theXML = [[NSString alloc]
initWithBytes: [webData mutableBytes]
length:[webData length]
encoding:NSUTF8StringEncoding];
我得到的字符串是
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<GetCategoryResponse xmlns="http://tempuri.org/">
<GetCategoryResult>
<Root>
<Record>
<catid>1</catid><catname>Hi</catname><catlogo>http://10.25.4.49/monsoonstore/Category/50X50.GIF</catlogo>
</Record>
</Root>
</GetCategoryResult>
</GetCategoryResponse>
</s:Body>
</s:Envelope>
因为我无法让任何解析器读取我从 web 服务获得的 NSData,所以我将上面的字符串转换为以下字符串(即我需要的确切 xml)
<Root><Record><catid>1</catid><catname>Hi</catname><catlogo>http://10.25.4.49/monsoonstore/Category/50X50.GIF</catlogo></Record></Root>
CXMLDocument *doc = [[CXMLDocument alloc] initWithXMLString:check options:0 error:nil];
NSArray *items = [doc nodesForXPath:@"//Root" error:nil];
for (CXMLElement *item in items)
{
NSLog(@"Root");
NSArray *titles = [item elementsForName:@"Record"];
for(CXMLElement *title in titles)
{
NSLog(@"Record");
break;
}
NSArray *categories = [item elementsForName:@"catid"];
for(CXMLElement *category in categories)
{
NSLog(@"catid");
break;
}
NSArray *artists = [item elementsForName:@"catname"];
for(CXMLElement *artist in artists)
{
NSLog(@"catname");
break;
}
.
.
.
.
Root 和 Record 日志被调用,而 catid 从未被调用.. 我可能做错了什么?