TouchXML, get text value of node objective-c
I've looked all over the web but just can't figure out how to get the text from a node in Objective-C. I'm using TouchXML and I am getting my node list. I want the title text from a node, but instead I get a node object. My code is:
resultNod开发者_如何学运维es = [xmlParser nodesForXPath:@"SearchResults/SearchResult" error:&err];
for (CXMLElement *resultElement in resultNodes) {
NSString *value = [resultElement elementsForName:@"Title"];
}
If I log the value to the console I get:
<CXMLElement 0x3994b10 [0x39732a0] Title <Title HtmlEncoded="true">test question</Title>>
I want the text, i.e test question
instead. I am banging my head against a brick wall here.
Since there should atleast one element in "resultElement" for the given value"Title", you can probably access it by adding following line of code:
NSString *value = [[[resultElement elementsForName:@"Title"] objectAtIndex:0] stringValue];
Try:
NSString *value = [[resultElement elementsForName:@"Title"] getStringValue];
精彩评论