Looks like literal XPath expressions (are they call that way?) are not supported by SimpleXML.

For example : /node/title is OK, but "my fixed title" is not. So what if I want to map constant, string values to one field?

It makes no sense for title, of course, but as I am planning to implement mappers for language and other fields, I need this feature as my feeds don't always have a lang attribute inside (which would be undoubtly more convenient : a simple /node/@lang expression would do the job, then).

I have found this post (http://drupal.org/node/845426) which says "pretty soon, each field will be able to select its own parser type". That would solve my problem indeed.

However, I couldn't wait, so I've added a few lines to the FeedsXPathParser.inc file, just below _query() function :

<?php
private function _query($xml, $query) {
  // bypath XPath query if $query is surrounded by simple quotes, like: 'fr', 'en' or 'whatever'
  if (preg_match('/^\'(.*)\'$/', $query, $matches)) {
    return array(array(new SimpleXMLElement('<string>' . $matches[1] . '</string>')), NULL);
  }
  // ...
?>

This is a dirty hack (which doesn't care about escaping quotes at all) but it allows me to specify a simple string as a source to set a node's field to a constant value.

Is there another, simpler way to achieve this? Am I missing something?

Comments

Sylvain_G’s picture

subscribe

twistor’s picture

One problem is that the string() xpath function isn't supported in php. A simple way around this issue would be #908870: Inherit properties from parent feed node (CCK fields).

twistor’s picture

Assigned: Unassigned » twistor
Status: Active » Fixed

Support for literals is now in dev. So, "My fixed title" should work. I'm looking for feedback on the new version.

Status: Fixed » Closed (fixed)

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

rj’s picture

string() is working for me with one caveat, I needed to disable feeds_xpathparser, clear cache, and then install dev, otherwise I had the WSOD.