My favorites | Sign in
Project Home
READ-ONLY: This project has been archived. For more information see this post.
Search
for
  Advanced search   Search tips   Subscriptions
Issue 50: CXMLNode nodesForXpath returns 0 items
1 person starred this issue and may be notified of changes. Back to list
Status:  Invalid
Owner:  ----
Closed:  Feb 2009


 
Reported by wh.haanstra, Feb 14, 2009
What steps will reproduce the problem?
1. I created a simple XML file and put it in a NSString. Load it in a
CXMLDocument.

NSString* xmlData = @"<Root><Item><Text>Small
Text</Text></Item><Item><Text>Small Text 2</Text></Item></Root>";
CXMLDocument* xmlDocument = [[CXMLDocument alloc] initWithXMLString:xmlData
options:0 error:nil];

2. First try to get the Item elements, and after that, try to get the Text
elements inside those items.
	NSArray* resultNodes = [xmlDoc nodesForXPath:@"//Item" error:&error];
for (CXMLNode* node in resultNodes)
{
	NSArray* textNodes = [node nodesForXPath:@"./Text" error:&error];
}
 
3. The array will never contain any nodes. I tried "./Text", "Text",
"/Text", "Item/Text", "./Item/Text". 

What is the expected output? What do you see instead?
The textNodes array should contain 1 "Text" node.

What version of the product are you using? On what operating system?
Revision 264. Also tried TouchXml 1.0 and 1.0.1.
Operating system: iPhone OS 2.2.1, Mac OSX 10.5.6

Please provide any additional information below.


Feb 14, 2009
#1 wh.haanstra
Reusing the "resultNodes" NSArray where I define the textNodes NSArray does work.
What am I missing?
Feb 28, 2009
Project Member #2 jwight
No idea. It works just fine for me:

NSString *xmlData = @"<Root><Item><Text>Small Text</Text></Item><Item><Text>Small Text 
2</Text></Item></Root>";
CXMLDocument* xmlDocument = [[CXMLDocument alloc] initWithXMLString:xmlData options:0 error:nil];
NSError *theError;
NSArray *theNodes = [xmlDocument nodesForXPath:@"//Item" error:&theError];
NSLog(@"Nodes: %@", theNodes);
NSLog(@"Error: %@", theError);

Prints out:

2009-02-28 13:52:07.061 TouchXML_Demo[31596:10b] Nodes: (
    <CXMLElement 0x1005f80 [0x1006570] Item <Item><Text>Small Text</Text></Item>>,
    <CXMLElement 0x1007d60 [0x1006660] Item <Item><Text>Small Text 2</Text></Item>>
)
2009-02-28 13:52:07.063 TouchXML_Demo[31596:10b] Error: (null)
2009-02-28 13:52:07.063 TouchXML_Demo[31596:10b] 
#####################################################################################
#############

Status: Invalid

Powered by Google Project Hosting