Hi. I have a view, and I've successfully generated custom XML feed using Node Feed module. If I try to attach the feed to a page, however, I get a blank page. I suspect it's a fatal PHP error, but I don't have the ability to set PHP error flagging on this server.

Any idea what this could be?

Drupal: 6.14
PHP 5.2.6
MYSQL: 5.0.45
Views Node Feed: 6.x-1.x-dev

Here is the wrapper template:

<?php print "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>"; ?>
<nodes>
***VIEWS_NODE_FEED_ITEMS***
</nodes>
<?php drupal_set_header('Content-Type: text/xml; charset=utf-8'); ?>

Here's the node template:

<?php
// common vars
$taxArr = $node->taxonomy;
?>

<node type="<?php print $node->type ?>" id="<?php print $node->nid ?>">
<title><?php print $node->title; ?></title>
<kind><?php foreach( $taxArr as $v ) { if ( $v->vid == 2 ) { print $v->name;} }?></kind>
<categories>
<?php 
foreach( $taxArr as $v ) { 
    if ( $v->vid == 1 ) {
        print "<category>". htmlentities($v->name) . "</category>\n"; 
    }
} 
?>
</categories>
<url><?php print $node->field_url[0][value]; ?></url>
<featured><?php print $node->field_featured[0][value]; ?></featured>
<short-desc><?php print $node->field_sd[0][value]; ?></short-desc>
<long-desc><?php print $node->field_ld[0][value]; ?></long-desc>
</node>

Comments

andrewlevine’s picture

The 6.x branch is largely untested. wouldn't recommend using it in production until there is a point release.

thomas4019’s picture

I am using the 6.x-dev module to produce an xml file. It seems to be working well. Now drupal is saying this module version is unsupported. Is there a better module to produce XML files from lists of nodes?

kahunacohen’s picture

Great module. Thanks for working on it. Any idea when this would be prod-ready? Any alternatives? Should I write a theme instead?

It has worked (with a few odd glitches), but pretty much does what it is supposed to, other than attaching to a page.

andrewlevine’s picture

Priority: Critical » Normal

@Thomas4019 and @kahunacohen - Please check out the warning on the project page and decide whether this module is right for you. There are a few other options I know of to make custom XML feeds
- Make your own menu hook and callback function, print out the XML and exit
- Make your own views style plugin (http://groups.drupal.org/node/10129)
- Retheme the output of a view and retheme the page tpl for this page to be an XML document

I currently don't have any time to work on the 6.x release, but I will review any patches.

kahunacohen’s picture

Thanks Andrew. Being a very new Drupal developer, could you briefly explain pros/cons of these three approaches:
- Make your own menu hook and callback function, print out the XML and exit
- Make your own views style plugin (http://groups.drupal.org/node/10129)
- Retheme the output of a view and retheme the page tpl for this page to be an XML document

Thanks!

andrewlevine’s picture

- Make your own menu hook and callback function, print out the XML and exit
Pros: Completely custom, get exactly what you want with best performance. Cons: Completely custom, you have to do everything yourself.
- Make your own views style plugin (http://groups.drupal.org/node/10129)
Pros: Uses views interface to build the queries. Cons: You need to learn how to write a views style plugin
- Retheme the output of a view and retheme the page tpl for this page to be an XML document
Pros: All you have to know is how to retheme. Cons: It's not resuable...It's sort of a hack.

kahunacohen’s picture

Andrew:
So my organization will have to generate XML from arbitrary views, and the XML will have to be custom XML. I can't enforce a structure.

I guess I need something like node feed module, which is a views style plugin right? But I would need it to work for things like taxonomy instead of nodes. For example, I might have a simple view that outputs all the terms in a vocab. I'd want to be able to generate XML from that view, which I can't do using the node feed module because the terms are not nodes.

Performance is not much of a concern, since we'd always be caching the XML to file anyway.

1) Would it be possible to hack your node feed module to do this?
2) If not, what route would you suggest given the requirements.

Thanks!

andrewlevine’s picture

I don't think views supports selecting taxonomy terms. so you'd probably need to make a custom module

kahunacohen’s picture

Actually I can achieve what I want by doing something like this in the node template:

$foo = get_defined_vars(); 
print_r( htmlentities( $foo[row]->term_data_name));

This allowed me to get the taxonomy term name from a view listing taxonomy terms.

I also needed to get more information. like the description, which unfortunately I could not get. But from the row object I could get the tid, and query the database for more info. It kind of sucks, but it does what I need it to do, and performance is not a concern since I am caching to file anyway. At some point I will figure out how to do it the right way, but for now this gets the job done.