Hello,
I have an application where I use TouchXML in to load an XML file. So I have it like working 'so so'.
First the entire document is loaded and through xpath every item is loaded. (An item has this structure like)
Code:
<items>
<item>
<title>theTitle</title>
<desc>Description</desc>
</item>
<item>
<title>theTitle2</title>
<desc>Description2</desc>
</item>
</items>
If I NSLog a single element, I get an NSXMLElement with the folowing values:
Quote:
<CXMLElement 0x114f160 [0x117b920] item <item>
<title>theTitle2</title>
<desc>Description</desc>
</item>>
|
I thought, now I can do the xpath query on that element instead of the entire document, and that way get a title, but that does not seem to be possible?
If I xpath on the element containing the item with '//title' i get all titles of every item, not just the one i'm executing the xpath on.
My code (somewhat)
Code:
NSError *anError = NULL;
CXMLDocument *xml = [[CXMLDocument alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://www.theurl.com/news.rss"] options:0 error:&anError];
self.contentArray = [xml nodesForXPath:@"//item" error:nil];
//self.contentArray contains now every item
//The loop
for(CXMLElement *element in self.contentArray) {
NSLog(@"Element: %@", element); //Which contains the above quote
//Here i try to get the title value now with the xpath on 'element' instead of the intire document (is this the correct way to do this?)
CXMLNode *title = [element nodesForXPath:@"//title" error:nil];
//Now if I NSLog the title object, it seams to contain every title of every item, though it should contain only this one of the current item, or am i Wrong?
}
Hope someone can help me out, I'm trying to get this right for quite some time.