Drupal Views: Generate xml file
Asked Answered
F

5

7

Is there a views plugin that I can use to generate a xml file? I would like something that I could choose the fields I would like to be in the xml and how they would appear (as a tag or a attribute of the parent tag).

For example: I have a content type Picture that has three fields: title, size and dimensions. I would like to create a view that could generate something like this:

<pictures>
  <picture size="1000" dimensions="10x10">
    <title>
      title
    </title>
  </picture>
  <picture size="1000" dimensions="10x10">
    <title>
      title
    </title>
  </picture>
...
</pictures>

If there isn't nothing already implemented, what should I implement? I thought about implementing a display plugin, a style, a row plugin and a field handler. Am I wrong?

I wouldn't like do it with the templates because I can't think in a way to make it reusable with templates.

Firdausi answered 21/2, 2009 at 1:33 Comment(1)
If you completed this module, Can you please give me the code for this.Alleviate
H
7

A custom style plugin is definitely capable of doing this; I whipped one up to output Atom feeds instead of RSS. You might find a bit of luck starting with the Views Bonus Pack or Views Datasource. Both attempt to provide XML and other output formats for Views data, though the latter was a Google Summer of Code project and hasn't been updated recently. Definitely a potential starting point, though.

Heredia answered 21/2, 2009 at 5:26 Comment(1)
Thanks. I think I'll these modules as base to my module.Firdausi
F
2

You might want to look at implementing another theme for XML or using the Services module. Some details about it (from its project page):

A standardized solution for building API's so that external clients can communicate with Drupal. Out of the box it aims to support anything Drupal Core supports and provides a code level API for other modules to expose their features and functionality. It provide Drupal plugins that allow others to create their own authentication mechanisms, request formats, and response formats.

Also see: http://cmsproducer.com/generate-how-to-drupal-node-XML-XHTML

Floodgate answered 21/2, 2009 at 3:10 Comment(0)
C
1

In Drupal 8 the Services module is now part of core (RESTful Web Services). This will allow you to provide any entity in xml or json. Also with views.

Read more here: https://drupalize.me/blog/201401/introduction-restful-web-services-drupal-8

Costanza answered 17/1, 2016 at 17:20 Comment(0)
M
0

There is a somewhat old description of this process on the Drupal forums. It references Drupal 4.7 and 5.x. I suspect the steps for 5.x would be same technique if not same code for Drupal 6.

Manzoni answered 21/2, 2009 at 3:11 Comment(0)
G
0

if you use drupal 7 and a higher version of it you can use views data export module for export as xml,xls,... https://www.drupal.org/project/views_data_export

Groggy answered 20/11, 2018 at 18:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.