Hi,

I was really confused why Views Datasource did nothing until I started following the issues and found the Drupal 6 Views 2 patch/mod rewrite : http://drupal.org/node/307223

Then I found the XML patch

http://drupal.org/node/306066

And everything is working great.

However I was wondering if there is a way to determine the name of the tags and also if my views_datasource is working correctly.

I have a test XML to squirt out some custom CCK fields.
They are called 'header1' and 'tagline1' via their titles.

However the XML outputs their variable names as the tag as follows:

<node_data_field_header1_field_header1>Headline Here</node_data_field_header1_field_header1> <node_data_field_header1_nid>26</node_data_field_header1_nid> <node_data_field_header1_field_tagline1>Look out dudes</node_data_field_header1_field_tagline1> 

This will make it hard to parse as xml output (I'd like to pull it into Flash).
Is it possible to have the tags(?) as the Title of the node element?

eg.

<header1>Headline Here</header1> 
<nid>26</node> 
<tagline1>Look out dudes</tagline1> 

Is this just a set up issue, a technique or is more patching/coding required?
It seems a bit weird for it to output such meaty elements.

Being able to output the above would solve a whole barrel of problems.

Thanks.

Comments

Bensbury’s picture

Hi,

I didn't exactly figure it out but this is a very bad hack until someone smart can.

If you want cleaner tags I added the following php to the views-views-xml.tpl.php in modules/views_datasource:

line 50:   $label = str_replace('_value', '', str_replace("profile_values_profile_", '', $label)); //strip out Profile: from profile fields
  
Add:-->    

	  $labelStrip = array();
	  $labelStrip = end(explode("_", $label)); // return html string
	  $label = $labelStrip;
--------
	 
     if (is_null($value) || ($value === '')) continue;

I'm not a coder so ot beatings for lack of style please.

However it outputs:

<?xml version="1.0" encoding="UTF-8" ?> <!-- generator="Drupal Views_Datasource.Module" --> <nodes> <node> <nid>26</nid> <type>xml</type> <headline1>Headline</headline1> <nid>26</nid> <tagline1>This is the tagline</tagline1> </node> </nodes> 


Just don't use any underscores (_) in your CCK names.
mbutcher’s picture

The names are generated by Views in a way that minimizes (and should eliminate) the possibility of naming collisions. The result of this naming algorithm (when converted to XML) is the long XML tag names.

An XSLT transformation might be one way of handling this in a non-hackish way. That would require changes to the module (maybe a hook to call a post-processor on the XML data). A simpler solution (again using a post-processor hook) would be to create a mapping (an associative array) and then use strtr to transform element names.

Bensbury’s picture

I'd love to have a go at that but sadly I'm not a coder (hence my dodgy hack); and don't understand hooks and the other Drupal API internal organ juiciness.
I might get there one day but I have no idea what you just wrote about. :(

I'm a Flash Monkey who descended into the land of code as Flash forced me.
As I wanted to hook Flash up to a database I was introduced to PHP and then to Drupal as a potentially wonderful CMS to create a powerful combination.

I was figuring that the CCK Title must be stored in an array somewhere and could be plucked out separately when making the request. After all, Views displays the title in the Fields part of the user interface.

Anyway after my first adventure into Drupal code and hacking, I hope I can get up to speed with being able to write stuff for modules the correct way.

I'm good for helping with anything but there is a lot I'm not capable of yet.

jkopel’s picture

@egeos
Not that you can't make this work, but you might want to look at the services module and possibly the amfphp server.
It might be a better solution for you in terms of making the connection to flash.

Bensbury’s picture

Thanks jkopel.
I was really interested in Services and amfphp but plumbed for Drupal 6 over 5 for my baptism of fire into Drupal.

At that time Services/amfphp wasn't available for Drupal 6 but I thought it would catch up as many of the modules were becoming available for 6 at that time.

I've just seen Services available for 6 but amfphp is still in dev.
In fact amfphp mod looks like it has alway been in dev! What's that about?

I may have a go with Services/amfphp for my next project, hopefully in D6 by then.

Thanks for the suggestion though.

------------------------------- This is an update:

Services and amfphp now works in Drupal 6 but clouded in mystery.
I posted up a pack that has everything needed to get Flash talking to Drupal in Drupal 6.
Just drop in the modules.
I might get shot for breaking some kind of ettiquette but it makes sense for people who want to get things working.

You can find it here:
http://drupal.org/node/219365

allisterbeharry’s picture

Assigned: Unassigned » allisterbeharry

The option to use the field titles instead of field names will be in the next release.

fereira’s picture

I have run into the same issue as Bensbury.

First of all, I had tried using the services module, and it worked fine for producing web services that can be consumed by another Drupal site. However, in my case I trying to expose CCK nodes such that they can be consumed using a web service on a coldfusion site so I was using the soap_server module (which uses NuSoap). I had trouble getting it to produce a wsdl that the coldfusion site can use, so I tried using the views_datasource module.

Note in the original issue that the element tag names all begin with "node_data_field_header1". In my case I saw the same behavior; that the field names all began with the first field in the view. Here is a sample output (with some tags removed):

<nodes>
  <node>
    <nid><![CDATA[2635]]></nid>
    <node_data_field_faculty_imagepath_field_faculty_imagepath><![CDATA[people/rwa1-portrait.jpg]]>    </node_data_field_faculty_imagepath_field_faculty_imagepath>
    <node_type><![CDATA[faculty]]></node_type>
    <node_vid><![CDATA[2635]]></node_vid>
    <node_title><![CDATA[Allmendinger, Richard Waldron]]></node_title>
    <node_data_field_faculty_imagepath_field_faculty_fullname><![CDATA[Allmendinger, Richard Waldron]]></node_data_field_faculty_imagepath_field_faculty_fullname>
    <node_data_field_faculty_imagepath_field_faculty_department><![CDATA[Earth and Atmospheric Sciences (EAS)]]></node_data_field_faculty_imagepath_field_faculty_department>
  </node>
</nodes>

The first field in my view is "faculty_imagepath" with is prepended to all of the subsequent tags, even though those fields are not chicldren of "faculty_imagepath" and have nothing to do with "faculty_imagepath". Note the node_data_field_faculty_imagepath_field_faculty_fullname and node_data_field_faculty_imagepath_field_faculty_department
element names.

I'll take a look a the code today to see if I can come up with something that will just use the field names without the prefix from the first field name.

fereira’s picture

Another followup...

It appears that this issue is related to how Views constructs field names. This issue describes that problem a bit better http://drupal.org/node/389428

In one of the last comments Merlin indicates that $view->results should not be used (which is what views-view-xml.tpl.php is using) because using the first field name as a prefix was done by design. That means that if you reorder your field views and use a different field as the first field in the list that the label names will change. That makes it kind of hard to transform the xml with XSLT.

allisterbeharry’s picture

Yep that's right. The way I wrote the plugins is wrong in a lot of ways. But I grok Views a lot more now and I'm doing a restructured plugin that will have the option of using either then normal view fields (i.e.what you normally see in a view) or the raw field name and content(to avoid name collisions and also access data like datetimes in a machine readable format.) Plus proper theming so you can tweak the output using templates if needed. This is going to get committed like today (fingers crossed.)

allisterbeharry’s picture

Status: Active » Fixed

The 6.x-1.0-beta1 release let's you select either the ordinary Views field labels or the rab db query fields. You can use the normal Views UI to create the labels you want as XML element names

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

xaa’s picture

Hello Fereira,

could you let me know what you have done to display the element <![[CDATA]]> on your fields, please ?
Thank you