At the moment, the XML output for a multiple value field looks like

<field_resource_type>diagramexercisefiguregraphsimulationstudent activity</field_resource_type>

Any chance it could be something like

<field_resource_type>
  <item>diagram</item>
  <item>exercise</item>
  ...
</field_resource_type>

Thanks for the v.useful module,

DT

Files: 
CommentFileSizeAuthor
#7 1102298-multiple-values-support-7.patch1.47 KBrudiedirkx
PASSED: [[SimpleTest]]: [MySQL] 0 pass(es).
[ View ]
#5 1102298-d7_multiple_value_field_support-5.patch4.49 KBerikwebb
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch 1102298-d7_multiple_value_field_support-5.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]

Comments

BenK’s picture

Subscribing

idflood’s picture

Subscribing

Steven Jones’s picture

Category:bug» support

I suspect this is something that you could achieve by theming the field in some way?

dboune’s picture

Steven, you could, however consider template_preprocess_views_data_export_xml_body, which encodes the resulting field data to text.

Unless I am missing something, this means you can't write out the desired xml and have it properly parse since any additional entities you add will be treated as text.

I think this ticket should be changed to feature request.

In my case, the desirable behavior would be to provide a mechanism to prevent encoding of a particular field such that the use of a field template in this way would work. At least, that seems appropriate at the moment.

I wanted to print the image URL, along with the alt and title text, for each image assigned to a particular multi-value image field. I accomplished this using a views field template, and modified the above mentioned function of views_data_export to allow for it.

erikwebb’s picture

Version:7.x-3.0-beta2» 7.x-3.x-dev
Category:support» feature
Status:Active» Needs review
StatusFileSize
new4.49 KB
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch 1102298-d7_multiple_value_field_support-5.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]

I've created a relatively clean solution that works generically for any multi-valued field. I'm not sure we want to override any of the separators (as I've done here), but this certainly keeps more with the overall philosophy and design of XML.

Here is the sample output -

<?xml version="1.0" encoding="UTF-8" ?>
<nodes>
  <node>
      <Title>Test (with words)</Title>
      <Body></Body>
      <Words>
        <item>One</item>
        <item>Two</item>
        <item>Three</item>
        <item>Four</item>
        <item>Five</item>
      </Words>
  </node>
  <node>
      <Title>Sample page</Title>
      <Body></Body>
      <Words>Sample</Words>
  </node>
</nodes>
das-peter’s picture

I just struggled over this and was thinking about how I could extend the options supplied by views_handler_field_field::multiple_options_form() when views data export is used.
I'd love to see a new option there like "XML child containers" with the ability to define the container name.
Unfortunately I can't think of a nice and generic way how to hijack that configuration.
If someone has an idea, let me know! :) In the meantime I'll probably use the approach of #5 - thanks for that!

rudiedirkx’s picture

StatusFileSize
new1.47 KB
PASSED: [[SimpleTest]]: [MySQL] 0 pass(es).
[ View ]

I've taken a different approach. I very much dislike my XML structure depending on its content. It feels wrong. It shouldn't sometimes look like

      <Words>
        <item>One</item>
        <item>Two</item>
        <item>Three</item>
        <item>Four</item>
        <item>Five</item>
      </Words>

and other times like

      <Words>Sample</Words>

and other times like

      <Words></Words> or <Words/>

My solution is simpler IMO: reuse the <Words> element. XPath will understand and the structure is always the same.

<?xml version="1.0" encoding="UTF-8" ?>
<nodes>
  <node>
      <Title>I have a body and several words</Title>
      <Body>Look at my body!</Body>
      <Words>One</item>
      <Words>Two</item>
      <Words>Three</Words>
  </node>
  <node>
      <Title>I have no body and 1 word</Title>
      <Words>Sample</Words>
  </node>
  <node>
      <Title>I have no body and no words</Title>
  </node>
</nodes>

There's one potential downside (not in my case): if a field contains 0 values, there will be no output for the field, not even <Words/>. Exampled above in Body and Words.

donundeen’s picture

#7 patch worked great for me,
however, when there's lots of other XML going on (I've also implemented the field-collections patch, which rubs up against this one),
if there's a comma in your xml, and you've got a , as your separator, you'll have problems.

So, for those multiple-value fields I wanted to have as separate XML elements, I had to make a very unique separator. then all was good.

chOP’s picture

I like you're approach here, except for one thing. I don't agree that when an element is empty, you should simply omit it. The structure of the xml document should be consistent. If an element is empty, output it as empty. Omitting it entirely may lead to confusion and is certainly not best practice.

I'm not sure how all that translates when writing an XSD. Perhaps we should check.

Steven Jones’s picture

Status:Needs review» Needs work
Issue tags:+Needs tests

Good work guys, sorry we've been somewhat absent from the issue queue.

The patch in #7 looks like a very promising way to go. This needs some tests though to cover the expected functionality, so marking back to needs work.

rudiedirkx’s picture

@chOP Then how would you print an empty element? <Words />? But then it has a value (1 empty value). I think it's alright if it just doesn't exist. 0 values = no trace anywhere. I have no idea how you would define that in XSD.

juliusvaart’s picture

The patch is working on both 3.0 Beta 6 and latest Dev but i get an error for every row:

Notice: Undefined property: views_handler_field_node::$multiple in template_preprocess_views_data_export_xml_body() (regel 390 van ../sites/all/modules/views_data_export/theme/views_data_export.theme.inc).

What could be causing this?

interdruper’s picture

Issue summary:View changes

About #12, I could reproduce the error too. A check is required for the 'multiple' property of the field.

Just change this line of the patch:

if ($views_field->multiple && $views_field->options['multi_type'] == 'separator') {

to

if (isset($views_field->multiple) && $views_field->options['multi_type'] == 'separator') {

By the way, patch #7 works fine for me.

rudiedirkx’s picture

You might want to check for !empty($views_field->multiple) instead of just isset(), because multiple could be FALSE.