Home > Archive > PHP Smarty Templates > December 2004 > Displaying xml
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| George Pitcher 2004-12-07, 4:23 am |
| Hi,
I'd like to display my results as an xml page. Is there a way I can do this
using Smarty (in use for the rst of my sites)?
My tpl file looks like this:
<?xml version='1.0' encoding='utf-8'?>
<Documents>
<result_size>{$itemcount}</result_size>
{section name=nr loop=$results}
<record id='{$results[nr].tr_id}'>
<AUTHOR>{$results[nr].sa}</AUTHOR>
{$results[nr].sa}
<TITLE>{$results[nr].st}</TITLE>
{$results[nr].ea}
<FRAGMENT_AUTHOR>{$results[nr].ea}</FRAGMENT_AUTHOR>
{$results[nr].vol}
<FRAGMENT_TITLE>{$results[nr].et}</FRAGMENT_TITLE>
{$results[nr].pagerange}
<VOLUME>{$results[nr].vol}</VOLUME>
<ISSUE>{$results[nr].issue}</ISSUE>
<PAGERANGE>{$results[nr].pagerange}</PAGERANGE>
</record>
{/section}
</Documents>
The web result looks like (for one record):
Bryman, Alan Bryman, Alan Chapter 5: The debate about quantitative and
qualitativ 93-126
and the 'view source' is like:
<?xml version='1.0' encoding='utf-8'?>
<Documents>
<result_size>5</result_size>
<record id='50450'>
<AUTHOR>Bryman, Alan</AUTHOR>
<TITLE>Quantity and quality in social research</TITLE>
<FRAGMENT_AUTHOR>Bryman, Alan</FRAGMENT_AUTHOR>
<FRAGMENT_TITLE>Chapter 5: The debate about ...</FRAGMENT_TITLE>
<VOLUME></VOLUME>
<ISSUE></ISSUE>
<PAGERANGE>93-126</PAGERANGE>
</record>
....
</Documents>
Cay anyone point me in the right direction please?
George in Oxford
| |
| Matthew Weier O'Phinney 2004-12-07, 4:23 am |
| * George Pitcher <george.pitcher@ingenta.com>:
> I'd like to display my results as an xml page. Is there a way I can do this
> using Smarty (in use for the rst of my sites)?
>
> My tpl file looks like this:
>
<snip - tmpl>
>
> The web result looks like (for one record):
>
> Bryman, Alan Bryman, Alan Chapter 5: The debate about quantitative and
> qualitativ 93-126
>
> and the 'view source' is like:
>
> <?xml version='1.0' encoding='utf-8'?>
> <Documents>
> <result_size>5</result_size>
> <record id='50450'>
> <AUTHOR>Bryman, Alan</AUTHOR>
> <TITLE>Quantity and quality in social research</TITLE>
> <FRAGMENT_AUTHOR>Bryman, Alan</FRAGMENT_AUTHOR>
> <FRAGMENT_TITLE>Chapter 5: The debate about ...</FRAGMENT_TITLE>
> <VOLUME></VOLUME>
> <ISSUE></ISSUE>
> <PAGERANGE>93-126</PAGERANGE>
> </record>
> ...
> </Documents>
>
> Cay anyone point me in the right direction please?
Looks to me like it's working fine, and that the issue is your browser's
display of XML.
We create XML using Smarty regularly with no issues. Until recently,
when we previewed in Firefox we could only see the actual data (no
tags); recent builds of Firefox -- with the developer tools enabled --
display a nice XML tree.
If ever in doubt, simply look at the source code sent to your browser;
if it looks correct, Smarty is doing its work, then.
Now, another possibility that I can see here is that you might want to
use XSLT to transform the XML into HTML or XHTML (which seems silly --
why not just send HTML back to the browser). If that's the case, you're
going to need to do a lot more, and this isn't the place to discuss it.
--
Matthew Weier O'Phinney | mailto:matthew@garden.org
Webmaster and IT Specialist | http://www.garden.org
National Gardening Association | http://www.kidsgardening.com
802-863-5251 x156 | http://nationalgardenmonth.org
|
|
|
|
|