大家好我想尝试使用TBXML
解析XML SOAP响应,但我找不到根元素来进行解析。这是我的代码:
TBXML *tbxml =[TBXML tbxmlWithXMLString:theXML];
TBXMLElement *root = tbxml.rootXMLElement;
NSLog(@"root: %@",[TBXML elementName:root]);
TBXMLElement *rootElement = [tbxml rootXMLElement];
TBXMLElement *rootItemElem = [TBXML childElementNamed:@"item" parentElement:rootElement];
if(root)
{
TBXMLElement *subcategoryEle = [TBXML childElementNamed:@"item" parentElement:root];
NSLog(@"item: %@",[TBXML elementName:subcategoryEle]);
while (subcategoryEle)
{
TBXMLElement * price = [TBXML childElementNamed:@"price" parentElement:subcategoryEle];
TBXMLElement *color = [TBXML childElementNamed:@"color" parentElement:subcategoryEle];
TBXMLElement * rating = [TBXML childElementNamed:@"rating" parentElement:subcategoryEle];
NSString *color = [NSString stringWithCString:[[TBXML color] cStringUsingEncoding:NSISOLatin1StringEncoding] encoding:NSUTF8StringEncoding];
NSLog(@"colorstr %@",color);
}
}
我遇到的问题是它没有进入WHILE
循环。有什么建议吗?