Issue 42: nodesForXPath does not return a specific item
Status:  Invalid
Owner: ----
Closed:  Feb 2009
Reported by surut...@gmail.com, Jan 10, 2009
What steps will reproduce the problem?
1. Create an XML file or use the attached output (part of a sample file)
that has repeating elements. Use nodesForXPath and extract all of them into
an array
2. Extract one element from the array and use nodesForXPath to extract a
specific attribute from the array
3. nodesForXPath returns an array containing all the attributes across all
the elements found in step 1

What is the expected output? What do you see instead?
Expected to see just one attribute but seeing all the attributes

What version of the product are you using? On what operating system?
Using the latest version with iphone SDK 2.2. Works fine with
NSXMLDocument/nodesForXPath. Attached sample contains is the result of
parsing an XML file and extracting all the elements (Step 1 above has been
done)


Please provide any additional information below.


XML-SAMPLE.rtf
5.7 KB   Download
Feb 28, 2009
Project Member #1 jwight
Please reopen or create a new bug and provide source code and sample data.
Status: Invalid
Mar 1, 2009
#2 surut...@gmail.com
Hi,

Why do you think it is invalid ? I have code that exhibits this behavior. I have
worked around now. Attached is the function that i use to extract from itemsResult
which has the data. This data comes from the Amazon search API. The last line in the
code should have objectAtIndex:0 like what i used to have if i use the Apple's code
in the iPhone simulator. 

I already provided the data before. Let me know what more you want..
StringForPath.rtf
1.9 KB   Download
Mar 2, 2009
Project Member #3 jwight
The sample XML code (from first attachment) is USELESS. It is just a bunch of logging information from the a run.

If you want this issue investigated further please provide SOURCE XML and a better description of the problem.
Mar 2, 2009
#4 surut...@gmail.com
Sorry for not being clear. I have attached an XML document that was received in
repsonse to a HTTP request. You can see that there are ten elements (Item) repeating
itself and each element has a set of attributes from which i want to extract some
e.g., Title.

So, i do the following:
 
doc = [[CXMLDocument alloc] initWithData:responseData options:0 error:&error];
itemResult = [doc nodesForXPath:itemRequired namespaceMappings:nameSpace error:&error];

itemResult is an array of XMLnodes.

n = [itemResult objectAtIndex:num];

NSString *item = [NSString stringWithFormat:@"//nameSpaceKey:%@", xp];
NSArray *nodes = [n nodesForXPath:item namespaceMappings:nameSpace error:&error];

"n" is the nth element (Item in the XML file). What i expect now in nodes is that the
"Title" of the "nth" element. Instead what i get is that the "Title" from all elements. 

[nodes objectAtIndex:num]

would give me the right title result. When i use NSXMLdocument, all i get is just one
title in the nodes array and i would do always

[nodes objectAtIndex:0]

At least this is what the standard code that i found in a book/web does. Why does
CXML behave differently ? What am i missing ? Sorry if i am still not clear. I filed
the bug only to understand things better..


TouchXML.rtf
8.0 KB   Download