Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 08-03-2009, 04:50 PM   #1 (permalink)
Registered Member
 
Join Date: Jul 2009
Posts: 10
Default [TouchXML] Value of contents within CXMLElement tag

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.
Matthijn is offline   Reply With Quote
Old 01-01-2010, 02:08 PM   #2 (permalink)
Registered Member
 
Join Date: Jan 2010
Posts: 8
Smile Wrong startPoint

According to this site, you are using the wrong syntax, as // starts looking from where you are onwards the end of the document.

The correct syntax should be @".item

Hope it helps


Quote:
Originally Posted by Matthijn View Post
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:



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.
muallin is offline   Reply With Quote
Reply

Bookmarks

Tags
touchxml, xml, xml parsing, xmlparser

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 242
14 members and 228 guests
ADY, AragornSG, Dani77, Dattee, Duncan C, HDshot, HemiMG, Promo Dispenser, Punkjumper, Rudy, sacha1996, sneaky, spiderguy84, theone8one
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,885
Threads: 89,231
Posts: 380,768
Top Poster: BrianSlick (7,129)
Welcome to our newest member, bookesp
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 03:17 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0