0

I'm building a module and I need to get XML content over HTTP request.

The idea is to create nodes programmatically with the retrieved data from the xml file.

Can I do this?

4
  • Are you looking for drupal_http_request()? Feb 2 '15 at 16:20
  • @AdamBalsam I think so, should I add special parameters for requesting a xml file?
    – chefnelone
    Feb 2 '15 at 16:34
  • I don't think you'd need any parameters at all except for the first ($url) parameter: $request = drupal_http_request('http://domain.com/xml_file.xml');. The XML file would be in $results->data. Feb 2 '15 at 22:55
  • With just the $url parameter works but then there are rare characters in the texts. That's the reason I think I need the "header" parameter.
    – chefnelone
    Feb 3 '15 at 7:55
3

Its a little bit of a learning curve , but I would recommend using the feeds module for this

https://www.drupal.org/project/feeds

you can then load xml (or csv) to nodes, and map its contents to nodes. This is preferable to writing your own custom functionality.

but if you do, drupal_http_request(), and then node_save() for constructing the nodes would be the way to do things. If you do code it yourself, Id recommend getting comfortable with running scripts with drush, as that'll be easier than battling timeouts in the browser

5
  • With feeds, don't you also need the Feed XPath module for injest XML?
    – mpdonadio
    Feb 2 '15 at 17:01
  • I used feeds before but I need to manipulate the data, then is not an option afaik.
    – chefnelone
    Feb 2 '15 at 17:01
  • You can integrate your own code with feeds using the API it supplies. The main advantage is being able to backout and re-run the import process which is very helpful while testing. Feb 2 '15 at 17:20
  • As @MPD mentions the Feed XPath module is needed. Here a very good video tutorial to use it: youtube.com/watch?v=n7LxjxwXtrc&feature=youtu.be
    – chefnelone
    Feb 3 '15 at 7:52
  • @chefnelone The Feeds Tamper module can be used to manipulate data w/o needing custom code agains the Feeds API.
    – mpdonadio
    Feb 3 '15 at 14:19

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.