diff --git a/plugins/views_data_export_plugin_style_export_xml.inc b/plugins/views_data_export_plugin_style_export_xml.inc index 378af77..e5f1117 100644 --- a/plugins/views_data_export_plugin_style_export_xml.inc +++ b/plugins/views_data_export_plugin_style_export_xml.inc @@ -130,20 +130,36 @@ class views_data_export_plugin_style_export_xml extends views_data_export_plugin 'formatter that outputs properly formatted and '. 'encoded XML data.'), ); + + if (empty($this->options['cdata_wrapper'])) { + $this->options['cdata_wrapper'] = array(); + } + + $form['cdata_wrapper'] = array( + '#type' => 'checkboxes', + '#title' => t('Fields value to wrapped using CDATA'), + '#options' => $options, + '#default_value' => $this->options['cdata_wrapper'], + '#description' => t('If checked the fields content will be wrapped using the CDATA tag.'), + ); } } /** - + * Perform any necessary changes to the form values prior to storage. - + * There is no need for this function to actually store the data. - + * - + * @param $form - + * @param $form_state - + */ + * Perform any necessary changes to the form values prior to storage. + * There is no need for this function to actually store the data. + * + * @param $form + * @param $form_state + */ function options_submit(&$form, &$form_state) { if (isset($form_state['values']['style_options']['no_entity_encode'])) { // Remove any options values set to 0 $form_state['values']['style_options']['no_entity_encode'] = array_filter($form_state['values']['style_options']['no_entity_encode']); } + if (isset($form_state['values']['style_options']['cdata_wrapper'])) { + // Remove any options values set to 0 + $form_state['values']['style_options']['cdata_wrapper'] = array_filter($form_state['values']['style_options']['cdata_wrapper']); + } } } diff --git a/theme/views_data_export.theme.inc b/theme/views_data_export.theme.inc index ab64e63..3139b4d 100644 --- a/theme/views_data_export.theme.inc +++ b/theme/views_data_export.theme.inc @@ -379,6 +379,8 @@ function template_preprocess_views_data_export_xml_body(&$vars) { $no_encode = isset($style_options['no_entity_encode']) ? $style_options['no_entity_encode'] : array(); + $cdata_wrapper = isset($style_options['cdata_wrapper']) ? $style_options['cdata_wrapper'] : array(); + $vars['item_node'] = _views_data_export_xml_tag_clean($vars['options']['item_node']); foreach ($vars['themed_rows'] as $num => $row) { @@ -394,7 +396,13 @@ function template_preprocess_views_data_export_xml_body(&$vars) { array('<', '>'), array('<', '>'), $content); + } + // Perform wrapping the field data using the CDATA tag + // unless excluded by style options. + if ($cdata_wrapper[$field]) { + // Escape CDATA end sequence only. + $content = '', ']]]]>', $content) . ']]>'; } $vars['themed_rows'][$num][$field] = $content;