allen58992008 / touchcode

Automatically exported from code.google.com/p/touchcode
0 stars 0 forks source link

CXMLNode nodesForXpath returns 0 items #50

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
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.

Original issue reported on code.google.com by wh.haanstra on 14 Feb 2009 at 10:07

GoogleCodeExporter commented 8 years ago
Reusing the "resultNodes" NSArray where I define the textNodes NSArray does 
work.
What am I missing?

Original comment by wh.haanstra on 14 Feb 2009 at 10:18

GoogleCodeExporter commented 8 years ago
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] 
################################################################################
#####
#############

Original comment by jwight on 28 Feb 2009 at 6:52