Hello fellow Drupalers,

First, Thanks for a wonderful and useful module, it makes life a lot easier.

We are using Feeds with Feeds XPath Parser to parse an XML feed our affiliates provide for us.
We have custom content type with many CCK fileds, Xpath mappings are set and all in all the feed gets imported properly, except for one minor detail.

First, please take a look at an example of the XML file we're dealing with (to maintain simplicity, non-important XML nodes are removed)

<item>
  <enclosure url="http://www.example.com/path-to-image/image1.jpg" type="image/jpeg"/>
  <enclosure url="http://www.example.com/path-to-image/image2.jpg" type="image/jpeg"/>
  <enclosure url="http://www.example.com/path-to-image/image3.jpg" type="image/jpeg"/>
  <title>Demo title 1</title>
</item>

<item>
  <enclosure url="http://www.example.com/path-to-image/image1.jpg" type="image/jpeg"/>
  <enclosure url="null" type="image/jpeg"/>
  <enclosure url="null" type="image/jpeg"/>
  <title>Demo title 2</title>
</item>

Notice the difference between the two items, first one has all three enclosure URL attributes set to a valid value, while the second one has a value of "null" in 2nd and 3rd URL attribute.

Now on to the problem:

Our content type has an image field (field_feed_image) attached to it and the number of allowed values for this field is set to 3.

Under XPath XML parser settings we have this set as an query to retrieve those images

field_feed_image: enclosure[1]/@url
field_feed_image: enclosure[2]/@url
field_feed_image: enclosure[3]/@url

(we have mapped the same field three times)

Feed is imported properly when the item has URL in all three enclosures set to a valid value (first item in the above example XML).

However, items of the second type, with "null" in URL attribute, are not imported at all.

We get this warning when Feeds encounters that item Invalid enclosure: null
and that item is not imported at all.

The question is: How to ensure the entire item is not skipped if there are null enclosures in it?

We have tried the following query

enclosure[1]/@url[translate(text(),'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmn > opqrstuvwxyz')!='null']
enclosure[2]/@url[translate(text(),'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmn > opqrstuvwxyz')!='null']
enclosure[3]/@url[translate(text(),'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmn > opqrstuvwxyz')!='null']

to try and skip those fields which have null set for url attribute, but no luck.
We again receive the same error message when importing, and those items are skipped entirely.

Maybe our second query is not correct, se please forgive our ignorance, this is the first time we are using Xpath.

Any suggestions are welcome.

Thank you!

Comments

dizarter’s picture

Just a correction to the second query we have tried. An extra "greater then" sign smuggled in there somehow when copy/pasting the query

enclosure[1]/@url[translate(text(),'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')!='null']
enclosure[2]/@url[translate(text(),'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')!='null']
enclosure[3]/@url[translate(text(),'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')!='null']
twistor’s picture

Status: Active » Fixed

enclosure[./@url != 'null']/@url

Status: Fixed » Closed (fixed)

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