1

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:

resultNodes = [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.

Jason Plank
  • 2,336
  • 5
  • 31
  • 40
Adam Seabridge
  • 1,909
  • 1
  • 20
  • 27

2 Answers2

4

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];
anonymous
  • 41
  • 1
2

Try:

NSString *value = [[resultElement elementsForName:@"Title"] getStringValue];
Jason Plank
  • 2,336
  • 5
  • 31
  • 40
Smallpawn
  • 21
  • 2