I have my site set up to import CSVs and manual entry and exporting the key information into an XML feed/File using views data export. I have a problem when I need to add a group of fields. The user can add as many of these groups of fields as they need and they should appear in the output in a single row as nested items.
When I use field collections the output produces invalid XML or is stripped of all wrappers so that it is just plain text. I have tried custom template files in my theme but views data export strips out the tags.
Desired output
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<file_information xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<asset_data>
<upn>GBHIS3473610HD30P001</upn>
<title>My Title</title>
<version>Sunday 26th January</version>
<duration>00:00:30:00</duration>
<tc_in>10:00:00:00</tc_in>
<tc_out>10:00:30:00</tc_out>
<aspect_ratio>16:9</aspect_ratio>
<segment>
<sequence>1</sequence>
<tc_in>10.00.00.00</tc_in>
<tc_out>10.00.30.00</tc_out>
</segment>
<segment>
<sequence>2</sequence>
<tc_in>DMC</tc_in>
<tc_out>DMC</tc_out>
</segment>
<segment>
<sequence>3</sequence>
<tc_in>DMC</tc_in>
<tc_out>DMC</tc_out>
</segment>
<segment>
<sequence>4</sequence>
<tc_in>DMC</tc_in>
<tc_out>DMC</tc_out>
</segment>
</asset_data>
</file_information>
Actual output (rest of XML is fine)
<segment>
<sequence>
<section class="field field-name-field-sequence field-type-number-integer field-label-above view-mode-full">
<h2 class="field-label">sequence:&nbsp;</h2>
<div class="field-items">
<div class="field-item even">1</div>
</div>
</section>
</sequence>
<tc_in>
<section class="field field-name-field-tc-in field-type-hms-field field-label-above view-mode-full">
<h2 class="field-label">tc_in:&nbsp;</h2>
<div class="field-items">
<div class="field-item even">
<span class="hms hms-format-h-mm-ss">0:00:00</span>
</div>
</div>
</section>
</tc_in>
<tc_out>
<section class="field field-name-field-tc-out field-type-hms-field field-label-above view-mode-full">
<h2 class="field-label">tc_out:&nbsp;</h2>
<div class="field-items">
<div class="field-item even">
<span class="hms hms-format-h-mm-ss">0:00:30</span>
</div>
</div>
</section>
</tc_out>
<sequence>
<section class="field field-name-field-sequence field-type-number-integer field-label-above view-mode-full">
<h2 class="field-label">sequence:&nbsp;</h2>
<div class="field-items">
<div class="field-item even">2</div>
</div>
</section>
</sequence>
<tc_in>
<section class="field field-name-field-tc-in field-type-hms-field field-label-above view-mode-full">
<h2 class="field-label">tc_in:&nbsp;</h2>
<div class="field-items">
<div class="field-item even">
<span class="hms hms-format-h-mm-ss">0:00:00</span>
</div>
</div>
</section>
</tc_in>
<tc_out>
<section class="field field-name-field-tc-out field-type-hms-field field-label-above view-mode-full">
<h2 class="field-label">tc_out:&nbsp;</h2>
<div class="field-items">
<div class="field-item even">
<span class="hms hms-format-h-mm-ss">0:00:20</span>
</div>
</div>
</section>
</tc_out>
</segment>
So how can I customise the output or should I use something other than field collections?
contents of my field-collection-item.tpl.php
<sequence><?php print render($content['field_sequence']); ?></sequence>
<tc_in><?php print render($content['field_tc_in']); ?></tc_in>
<tc_out><?php print render($content['field_tc_out']); ?></tc_out>
contents of my views-data-export-xml-body.tpl.php
<?php
$item_item = 'asset_data';
?>
<?php foreach ($themed_rows as $count => $row): ?>
<<?php print $item_item; ?>>
<?php foreach ($row as $field => $content): ?>
<?php if($content != NULL){ ?>
<?php $content = str_replace("<","<",$content);
$content = str_replace(">",">",$content); ?>
<<?php print $xml_tag[$field]; ?>><?php print_r $content; ?></<?php print $xml_tag[$field]; ?>>
<?php } ?>
<?php endforeach; ?>
</<?php print $item_item; ?>>
<?php endforeach; ?>