Hello;

First of all to the developer of this, great work!

I am using xPathp Parser to parse a weather feed from Environment Canada
http://dd.weatheroffice.gc.ca/citypage_weather/xml/NS/s0000318_e.xml

This feed is odd in comparison to most simple XML, where sometimes if a field does not apply it won't appear in the feed. xPath Parser of course freaks out and won't parse anything. Is there anything that I can put into the query to prevent it from not parsing in this situation?

Any insights would be greatly appreciated.

Thanks;

-Ryan

CommentFileSizeAuthor
#10 data.osm_.zip1.39 KBgthoele

Comments

twistor’s picture

looking into it, thanks for the sample doc. It helps a lot.

twistor’s picture

Can you give me an example of your context and queries?

twistor’s picture

Also, if you could try using the dev version it solves the missing element issues my making the user provide a context expression first. That's the only way I could find to avoid this issue.

rbrownell’s picture

Hi;

Thanks for your responses. I did try the dev version, but I wasn't exactly sure where to start with the context expression. I am going to give it a stab and let you know what I encounter.

BTW, do you have a paypal donation form? I really would like to contribute some money to the project.

Thanks;

-Ryan

rbrownell’s picture

Status: Closed (fixed) » Active

That did it, thanks for your help!

It wouldn't be a bad idea to mention the context expression in the documentation that is being created for this module.

Would I be correct in assuming to pass the NA variable that in CCK the input type be set to text and the default value be "NA", so that when XPath Parser does not fill in a value CCK automatically fills it in?

Thanks;

-Ryan

rbrownell’s picture

Status: Active » Closed (fixed)

Closing...

rbrownell’s picture

rbrownell’s picture

Priority: Normal » Minor
rbrownell’s picture

Status: Active » Closed (fixed)

Issue resolved in most recent dev release.

gthoele’s picture

Version: 6.x-1.01 » 6.x-1.8
Component: Miscellaneous » Code
Category: support » feature
Status: Closed (fixed) » Active
StatusFileSize
new1.39 KB

Hello,

i've got a similar issue with nonexisting XML elements. The developer version worked for me as well, but broke around the time version 1.6 was released.

I am using XPath Parser to parse Openstreetmap geodata. The feed i am using is this (see attachment as well):
http://xapi.openstreetmap.org/api/0.6/node[power=generator][bbox=15,47,1...
(its a list of power plants)
My context query is /osm/node and my field querys look like @id or tag[k='operator']/@v.

A characteristic of Openstreetmap feeds is lots and lots of not-always-existing elements, which i want to resolve to an empty field in Drupal. Since 1.6 i'm getting error messages instead "There was an error with your Query"

A very dirty fix for this is (excerpt from FeedsXPathParser.inc from line 82) turning off error checking altogether:

if ($results === FALSE) {
      //throw new Exception(t('There was an error with the XPath query: <em>%query</em>', array('%query' => $query)));
    }
    return $results;

This works for me but is butt-ugly, and it is generating warnings further down in code (at line 111) for each empty element.

My favourite solution would be to use XPath querys that simply return empty strings for missing elements instead of errors. This could in theory be accomplished by enclosing the query in "string()" (which is an official XPath function which returns empty strings for nonexisting elements, perfect!), but PHPs XPath processor doesn't know how to deal with that function, see comment Nr. 4 on this page:
http://de2.php.net/manual/en/simplexmlelement.xpath.php

Hmmm. I can't really suggest a clean solution. Any Ideas?

Gunnar

twistor’s picture

Assigned: Unassigned » twistor
Category: feature » bug
Status: Active » Fixed

The is the problem: depending on the version on libxml used internally, it may return an empty array or FALSE. There's a workaround that I've implemented, I'm committing it to dev since initial tests seem to work properly. Thanks!

http://drupal.org/cvs?commit=431892

gthoele’s picture

Hi Twistor,

i tried the recent devel version and your workaround seems to work very well for parsing Openstreetmap data. Thanks!

Gunnar

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.