Problem/Motivation

Where a field for export contains valid xml, or is pushed through a field formatter that outputs valid xml, it would be nice to be able to exclude that field from xml encoding.

Proposed resolution

Add a new option to the views data export plugin for xml that allows you to specify fields that will be excluded from xml encoding. That way, if a user chooses a field formatter that already outputs valid xml, they can then exclude that field from xml encoding too.

User interface changes

The new "Exclude these fields from XML Entity Encoding" options can be added as checkboxes to the Style Options for the Views data export XML style plugin.

Original report by adam_b

I have a database which includes a lot of useful info in field-collection entities. When I try and export this in XML format, it's output as a table with escaped HTML tags, no matter what format I choose for the field (see attachment).

Is this an issue for this module, or for the field-collection module? Are there any alternatives? I can see ways to handle this, but ideally I'd like a full XML structure.

Files: 
CommentFileSizeAuthor
#25 views_data_export-1446102-disable-xml-encoding_outdated.patch6.97 KBdasjo
#22 views_data_export-1446102-xml-encoding.patch3.95 KBSteven Jones
#19 views_data_export-1446102-disable-xml-encoding.patch6.46 KBSteven Jones
PASSED: [[SimpleTest]]: [MySQL] 84 pass(es).
[ View ]
#17 views_data_export-1446102-disable-xml-encoding.patch4.08 KBSteven Jones
FAILED: [[SimpleTest]]: [MySQL] 81 pass(es), 0 fail(s), and 6 exception(s).
[ View ]
#6 views_data_export-disable_xml_encoding-1446102-6.patch4.24 KBchOP
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch views_data_export-disable_xml_encoding-1446102-6.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]
export_chef.xml_.txt6.36 KBadam_b

Comments

adam_b’s picture

bounce... anybody have any suggestions?

jpcurley25’s picture

struggling with the same problem myself.

jpcurley25’s picture

Status:Active» Closed (duplicate)
Thithi32’s picture

I don't really understand jpcurley25 answer.
I have the same kind of issue: i'd like to export an xml that would look like:
nodes
-node
--title
--medias
---media
----title
----file

Any idea on how to do this?

Thithi32’s picture

What I did was modify the xml export template (views-data-export-xml-body--myview-name--mydisplay-name.tpl.php) to insert another view inside my current view:

<?php foreach ($themed_rows as $count => $row): ?>
  <point_info>
<?php foreach ($row as $field => $content): ?>
<?php if ($field == 'field_medias'): ?>
<?php
        $view_name
= 'xml_medias';
        
$display_id = 'views-data-export';
       
$myargs = $row['nid'];
        print
views_embed_view($view_name,$display_id,$myargs);
   
?>

<?php else : ?>
<?php if (trim($content)!='' && $xml_tag[$field]!='') : ?>
    <<?php print $xml_tag[$field]; ?>><?php print $content; ?></<?php print $xml_tag[$field]; ?>>
<?php endif; ?>
<?php endif; ?>
<?php endforeach; ?>
  </point_info>
<?php endforeach; ?>

Hope this help someone.

chOP’s picture

Title:Exporting field collections (and other entities?)» Exporting fields that already output valid xml encoded content
Version:7.x-3.0-beta5» 7.x-3.x-dev
Category:support» feature
Status:Closed (duplicate)» Needs review
StatusFileSize
new4.24 KB
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch views_data_export-disable_xml_encoding-1446102-6.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]

Patch motivation

In my situation, I've written a field formatter that returns a render array that in turn outputs valid xml encoded content. When I apply this field formatter to my field for export, I want to be able to exclude the field from xml encoding by views_data_export_plugin_style_export_xml

Patch Solution

This patch adds checkboxes to views_data_export_plugin_style_export_xml::options_form(), where you can choose individual fields for exemption from xml entity encoding. Then, during the theme preprocessing in template_preprocess_views_data_export_xml_body() we check this setting before xml encoding each fields contents for inclusion in $themed_rows.

After applying the patch:

  1. Set-up a new view for export,
  2. Choose the Views Data Export - XML file format,
  3. Choose some fields for export,
  4. Edit the XML file Settings to choose which fields to exclude from XML entity encoding
  5. Click Update preview to see the changes

.

adam_b’s picture

#6 works great for me - thanks very much

donundeen’s picture

#5 this looks great, but I can't get it to work. Where does this file need to go?

I've my view name is
"Text and Media XML"
and the Display name is:
"Data export"

I've named my template file:
views-data-export-xml-body--text-and-media-xml--data-export.tpl.php
also tried:
views-data-export-xml-body--text_and_media_xml--data_export.tpl.php

is that right?

I put it in the same directory as the original views-data-export-xml-body.tpl.php ,

but the override isn't happening.
maybe there's something dumb I'm missing?

thanks.

Thithi32’s picture

@donundeen : the file goes in your theme like other template files. Are you sure your views name and display name are correct? -> look at your views 'advanced' group + Other + System Name (sorry I'm translating from french I'm not sure of the terms). For info, my files are named:
views-data-export-xml-body--xml-panos.tpl.php
views-data-export-xml-footer--xml-panos--views-data-export_1.tpl.php
views-data-export-xml-header--xml-panos--views-data-export_1.tpl.php
views-data-export-xml-body--xml-panos--views-data-export-1.tpl.php
views-data-export-xml-footer--xml-panos--views-data-export_2.tpl.php
views-data-export-xml-header--xml-panos--views-data-export_2.tpl.php
views-data-export-xml-body--xml-pi.tpl.php
views-data-export-xml-footer--xml-pi.tpl.php
views-data-export-xml-header--xml-pi.tpl.php
views-data-export-xml-footer--xml-panos.tpl.php
views-data-export-xml-header--xml-panos.tpl.php
views-view-field--xml-pi--field-video2.tpl.php

Thithi32’s picture

@donundeen: you can look at 'advanced' + Other + Theme Information to get the list of template files you can use.

Peacog’s picture

Thank you for the patch in #6. It's very useful and I'd love to see it committed.

In my case I needed to wrap a field in an additional tag. The patch allows me to create a template in my theme and simply wrap the output like this:
<mytag><?php print $output; ?></mytag>

pacproduct’s picture

Patch #6 works great for me as well. Thank you!
I needed it to embed a sub-view that already outputs some valid XML.

james.williams’s picture

Status:Needs review» Reviewed & tested by the community

Patch #6 works perfectly for me too.

joshf’s picture

#6 worked for me as well; thanks for the patch!

Steven Jones’s picture

Steven Jones’s picture

Status:Reviewed & tested by the community» Needs work
Issue tags:+Needs tests

This need some tests too.

Steven Jones’s picture

Status:Needs work» Needs review
StatusFileSize
new4.08 KB
FAILED: [[SimpleTest]]: [MySQL] 81 pass(es), 0 fail(s), and 6 exception(s).
[ View ]

Here's a re-roll for the test bot, still need to add tests.

Status:Needs review» Needs work

The last submitted patch, views_data_export-1446102-disable-xml-encoding.patch, failed testing.

Steven Jones’s picture

Status:Needs work» Needs review
Issue tags:-Needs tests
StatusFileSize
new6.46 KB
PASSED: [[SimpleTest]]: [MySQL] 84 pass(es).
[ View ]

How about this one. Fixes the notice and adds a test.

Steven Jones’s picture

Status:Needs review» Fixed

Thanks for the hard work everyone!

Committed to 7.x-3.x.

Steven Jones’s picture

Version:7.x-3.x-dev» 6.x-2.x-dev
Status:Fixed» Patch (to be ported)
Steven Jones’s picture

Status:Patch (to be ported)» Needs work
StatusFileSize
new3.95 KB

Here's a simple patch, that needs some work because the Views API changed from 3 -> 2.

loparr’s picture

Which patch can I use for drupal 6 version?

ts145nera’s picture

Thanks for your works.

I would know if there's a way to add custom tag to the field using "Rewrite the output of this field".
I've tried to add

<foo>[field_token]</foo>

but tags are been removed in the export

ts145nera’s picture

Issue summary:View changes

Add new summary outlining proposed solution.

dasjo’s picture

just for reference and our make file, attached is a patch against views_data_export 3.0-beta6 that includes the committed patch #20 and adapts it for xml exports

  • Steven Jones committed 6d48f4d on 7.x-4.x
    Issue #1446102 by chOP, Steven Jones: Added Exporting fields that...