allen58992008 / touchcode

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

Atom feeds problem with Xpath #40

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Create an CXMLDocument for an atom feed eg.
http://theraneman.blogspot.com/feeds/posts/default
2. CXMLDocument *rssParser= NULL;

    rssParser = [[[CXMLDocument alloc] initWithContentsOfURL:url options:0
error:nil] autorelease];
    titlearray = [rssParser  nodesForXPath:@"//title" error:nil];

What is the expected output? What do you see instead?
OF course there are title elements but the array count is 0. This works for
RSS feeds.

What version of the product are you using? On what operating system?
Using latest version on Mac 10.5.5

Please provide any additional information below.
Seems this is the problem of ATOM feeds with XPATH. Any help is appreciated.

Original issue reported on code.google.com by rane.abh...@gmail.com on 8 Dec 2008 at 7:21

GoogleCodeExporter commented 8 years ago
Update on this bug would be nice.

Original comment by thetazz...@gmail.com on 21 Jan 2009 at 3:01

GoogleCodeExporter commented 8 years ago
I'll look at bug as time/resources allow.

Don't forget that you have the access to all the source and the community would 
welcome any fixes.

Feel free to support TouchCode via http://toxicsoftware.com/touchcodedonate/ if 
that floats your boat.

Original comment by jwight on 21 Jan 2009 at 3:08

GoogleCodeExporter commented 8 years ago
Hi there,
After searching al lot in the cloud for this issue I realized that this was a 
problem
faced by several RSS client developers. For my iphone app I am now using 
NSXMLParser
which is just a light weight parser with no xpath support. 

Thanks
Abhang

Original comment by rane.abh...@gmail.com on 21 Jan 2009 at 5:33

GoogleCodeExporter commented 8 years ago
Closing.

Original comment by jwight on 28 Feb 2009 at 7:10

GoogleCodeExporter commented 8 years ago
I think this is related to issue #37, so I'm posting this information in that 
thread as well.

This issue is actually related to how libxml2 works. With atom feeds, the 
default namespace has to be defined 
and used in your XPath queries, or you have to construct your XPath queries so 
that they specifically handle 
the default namespace.

I figured this out from this page:
http://philwilson.org/blog/2007/11/parsing-atom-with-libxml2

Without defining any namespaces, you need to use this kind of XPath query:
//*[local-name()='feed']
instead of this:
//feed

Here's how you can define namespaces with TouchXML when querying for XPath. 
This example is against an 
atom feed generated by ADO.NET Data Services:

DataServiceParser *dataServiceParser = [[DataServiceParser alloc] 
                                            initWithContentsOfURL:urlUpdateDataService 
                                            options:0 error:&error];

    if(dataServiceParser) {
        NSArray *entries;

        NSDictionary *dictNameSpaceMappings = [[NSDictionary alloc]
                                               initWithObjects:[NSArray 
arrayWithObjects:@"http://www.w3.org/2005/Atom", 
@"http://schemas.microsoft.com/ado/2007/08/dataservices/metadata", nil]
                                               forKeys:[NSArray arrayWithObjects:@"atom", @"m", nil]];

        entries = [dataServiceParser nodesForXPath:@"/atom:feed/atom:entry/atom:content/m:properties"
                                 namespaceMappings:dictNameSpaceMappings error:&error];

So, I wouldn't consider this a bug or issue with TouchXML, it's just a 
technique you must use for atom feeds 
with any XML library based on libxml2.

Original comment by mitch.h...@gmail.com on 6 Jun 2009 at 11:52