1

I have a url www.example.com/123456, generated by a third party source. So there is not, at the time the user clicks, any node that corresponds to that URL. The six digit number at the end is an item id, which corresponds to the XML document http://example.com/item/123456/description.xml.

Is it possible to configure Feeds and the XPath parser to, when a user clicks on one of these links, to grab that six-digit number, and import the data from the XML document (by argument) into a node?

EDIT

Here is some code I tried to test, but I don't know if it can trigger on navigation to the "node" (which, remember, doesn't exist until import).

    //Trying to grab those last six digits, which are the ID I need to grab the XML file
    $idnr = $_GET['q']; 

    //Compare this ID to the aliases I have on already imported nodes so we don't import those again
    $nodeids = db_query('SELECT dst FROM {url_alias}'); 

    if(!in_array($idnr, $nodeids)){ 
    //Check if that ID is in the array. If not, create the node
          $node = new stdClass();
          $node->type = 'special_node';
          $node->status = 0;
          $node->path = $idnr;
          //I already have this feed set up for that particular content type and with XPath parser
          $node->feeds['FeedsHTTPFetcher']['source'] = 'http://www.source.com/' . $idnr . '/desc.xml';
          node_save($node); //Create the node
          $_REQUEST['destination'] = $node->path; //Redirect the user to the node
    } 

Is any of this feasible to do? Especially in a way that isn't disruptive to the client?

EDIT 2

I have WAY too many fields to map to use Feeds (100+). Does someone have an idea how I could use Migrate to import this XML data upon navigation to the URL?

  • Can you tell us what "normally" happens when the link is clicked? Does it do something in Drupal or is this just a link aggregated onto a page? That distinction matters to determine what method to use. – webkenny Feb 1 '13 at 5:29
  • The service this is connected to has a list of published items that are in one XML file, connected to their respective documents. Those I have imported with Migrate. Then the clients also want to be able to show unpublished items (not in the list XML file but its own XML has been published). So if the link belongs to a published item, you go to that node which has already been created. If it doesn't, you get a 404. But I want to trigger Feeds to import that node onclick for that link. – dodododo Feb 1 '13 at 6:46
  • EDIT 2 Enabled the module, but I ended up with a lot of empty nodes... – dodododo Feb 1 '13 at 7:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.