XML element names
| Project: | Views Datasource |
| Version: | 6.x-1.0-alpha2 |
| Component: | Code |
| Category: | support request |
| Priority: | normal |
| Assigned: | allisterbeharry |
| Status: | active |
Jump to:
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
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.

#1
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.
#2
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.
#3
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.
#4
@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.
#5
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
#6
The option to use the field titles instead of field names will be in the next release.