用TouchXML解析NSString?
|
我正在尝试解析使用SOAP从WebService接收到的字符串。
由于我无法解析从Web服务接收到的数据(我不知道为什么。.请在这里看看使用Soap Web Services解析XML),我正在将数据转换为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 and Record日志被调用,而catid从未被调用..我可能在做错什么?
没有找到相关结果
已邀请:
2 个回复
淑灯
至
我的意思是,搜索元素catid在记录下,而不在根下。 我上面的代码可能会给您带来编译错误,因为我还没有使用TouchXML,但是您知道我的意思。
链眷克袒姜
,根据您的指定,您需要一个可以由NSData直接创建的解析器。 NSXMLParser具有“ 6”,可通过发送NSData作为参数来返回NSXMLParser实例。
使用NSXMLParser在iPhone上解析XML。