-1

I have used Views Data Export to create XML files of the nodes and can filter and limit them as i wish. However, I need to create a separate XML file for row/node rather than have them combined in a single XML file/feed.

In addition to that ideally the file name should match the value of a certain field.

How do I go about it?

My first thoughts are to either: 1) Create a new module reads an XML feed created with Views Data Export and then parses the data and makes a new file from each item and uses the value of the ID field to name the file 2) Make a modified version of views data export and insert some code that would create a file for each record rather than a new row in a doc.

Is there a better 3rd option or module that already does this? If not which of the two options will be easier/best?

Example current output in single file:

<file_information xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <asset_data>
    <upn>SOMEID123</upn>
    <title>Some title 1</title>
  </asset_data>
  <asset_data>
    <upn>SOMEID124</upn>
    <title>Some title 2</title>
  </asset_data>
</file_information>

Desired output:

File name someid123.xml

<file_information xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <asset_data>
    <upn>SOMEID123</upn>
    <title>Some title 1</title>
  </asset_data>
</file_information>

File name someid124.xml

<file_information xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <asset_data>
    <upn>SOMEID124</upn>
    <title>Some title 2</title>
  </asset_data>
</file_information>

This is for internal project that only 2 people will ever use and is just to cut down on the amount of mindless manual copy and pasting so doesn't need to have optimum performance or handle many hits/vistors. The process will be import spreadsheet with many records export an xml file for each record. Whether these files get written to disk or download to user doesn't matter.

Thanks for any tips/advise

  • 2
    You can't create many outputs with one view triggering. That's simply not how Views works, it is a web-oriented module, and on the web one request means one response. You could split it outside Drupal. Or create view that takes node id and outputs single node in file. Or many other workarounds, but no way to directly do what you ask for. – Mołot Dec 12 '13 at 12:23
  • Thanks @Mołot - I thought that might be the case but was worried I was missing something simple like a loop/cron module/command that would loop through the action and churn out files but I guess not. I will try to write something separately that will parse the XML and create files for each row. – Keypad Dec 12 '13 at 14:48
  • Well, for example I used to have bash script that obtained list in XML format, and then obtained node UUIDs from that list. Then it looped over this list and produced per-node output. If that's what you want (aka good enough), maybe we can get somewhere. – Mołot Dec 12 '13 at 15:02
  • 1
    This is for internal project that only 2 people will ever use and is just to cut down on the amount of mindless manual copy and pasting so doesn't need to have optimum performance or handle many hits/vistors. The process will be import spreadsheet with many records export an xml file for each record. Whether these files get written to disk or download to user doesn't matter. – Keypad Dec 12 '13 at 15:07
  • Import your last comment to your question and I'll be able to start writing an answer ;) – Mołot Dec 12 '13 at 15:08
0

I wrote a script to parse the XML and split each of the nodes, add the header and footer xml, save them in separate files, zip them up and then provide a download link. Works pretty well but does add an extra step to the output.

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.