Hi there,
I've set up a Drupal website to output a View as XML which is to be used with a Flash slideshow. I have done so using various functions / suggestions I've found throughout the forums.
The XML can be seen here:
http://dev.goldcoastholidaypark.com.au/xml/12/slideshow.xml
The issue I've got is that Flash can't interpret the XML because of the "<div class="view view-gallery-xml">" and "<div class="view-content view-content-gallery-xml">" tags and their closing tags.
I can't for the life of me work out how to ensure that those tags are not output in the view?
Here is the code in my template.php file that is being used...
/** Custom Gallery XML View **/
function phptemplate_views_view_list_gallery_xml($view, $nodes, $type) {
$output ="";
foreach($nodes as $n) {
$output .= "<image img=\"/files/thumbnails/".$n->node_data_field_thumbnail_field_thumbnail_alt."\" />";
}
return $output;
}
As to ensure that the view is output as XML, I have a file called "page-xml.tpl.php" that is structured as follows...
<?php
drupal_set_header('Content-Type: text/xml; charset=utf-8');
print "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>";
print "<slideshow>";
print $content;
print "</slideshow>";
?>
There is a bit more stuff in that file, but you get the idea.
Any suggestions? I'm guessing it's probably something straight forward that I'm overlooking.
Comments
I believe those div tags are
I believe those div tags are coming from the default theming on view list items.
Have you tried using the complete override for all gallery_xml views?
phptemplate_views_view_gallery_xml($view, $type, $nodes, $level = NULL, $args = NULL) {...}instead of
phptemplate_views_view_list_gallery_xml($view, $nodes, $type) {...}Or is that not an option?
You are awesome! I thought
You are awesome! I thought I'd tried that but obviously not, just that simple change worked a charm!
I was halfway through putting some if statements in the views.module file to ensure they wouldn't be output, but that's a MUCH better solution!
Thanks heaps for your help. :)
I am trying the same thing.
I am tryin to replicate this also.
i put
into template.php
and created page-xml.tpl.php with the other code.. how do i call it though.. sorry i am pretty new to drupal still
why is your page called
why is your page called "page-xml.tpl.php"?
is there a tutorial anywhere
is there a tutorial anywhere to find...?
i really need well formed xml output!
thnx.
See if this helps any
http://drupal.org/node/104823
thank you, i will try that
thank you, i will try that again.
i bet this will work now.
the funny thing is that the link leads back to this thread, if you follow the trace...
:-)
how i created xml view in drupal 6
I was in need to generate an xml file for use in a flash photo gallery. I couldn't find one way to do it, so I came up with this way. If there is a better/easier method, please let me know.
the xml needed to be in this format:
Each photo album/gallery was coming from a content type of "gallery" that had an image field that let users upload multiple images per album. The thumb for each was created by imagecache using "scale and crop" action.
I created a new view for the node type of gallery. I used row style of node instead of fields. Changed the path to "gallery_xml/gallery.xml" .
I overrode these theme files for the view:
display output: views-view--gallery.tpl.php - to only show the rows
style output: views-view-unformatted--gallery.tpl.php - to remove and div styles
By Using the fields as nodes, I can theme the node file to output the gallery xml
node-view-gallery.tpl.php
Now I needed to get the GALLERIES root tag in the xml file.
I created a page-gallery_xml.tpl.php
Now by going to gallery_xml/gallery.xml, I got the correct xml layout. I changed the flash to grab the xml from this location, and all worked.
Hopefully this will help someone.
very ... very helpful
Thank you macdonaldj,
I am trying to make something similar (http://drupal.org/node/838938).
I followed your instructions but i can not set the page header to xml..
The source output is
GALLERIES> GALLERY TITLE =".." > /GALLERY>
GALLERY TITLE=".."> /GALLERY>
GALLERY TITLE=".."> /GALLERY>
GALLERY TITLE=".."> /GALLERY>
but in the display i have the following error
XML declaration allowed only at the start of the document
Please help.
Thank you anyway, again,
mike
for anyone who cares
the function
print ("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
leaves a blank space in the beggining
output:
<?xml version="1.0" encoding="utf-8"?>
instead of
<?xml version="1.0" encoding="utf-8"?>
This caused the problem.
The solution is to replace
print ("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
with
$xml = new DomDocument('1.0','utf-8');
Still further help appreciated:)
mike
If your templates aren't working
I was following these steps and couldn't get it to work. I figured it out after a day or so of messing around. In your view, in the information link, be sure to click "Rescan template files" after you've added the new template files or else Drupal won't recognize your files.
Thanks for this, it solved my XML output problems :)