<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Zend RESTful XML Generic Functions</title>
	<atom:link href="http://www.chrisdanielson.com/2009/10/12/zend-restful-xml-generic-functions/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.chrisdanielson.com/2009/10/12/zend-restful-xml-generic-functions/</link>
	<description>Trials and Tribulations of a Software Developer</description>
	<lastBuildDate>Mon, 30 Jan 2012 21:45:46 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Derek Martin</title>
		<link>http://www.chrisdanielson.com/2009/10/12/zend-restful-xml-generic-functions/comment-page-1/#comment-554</link>
		<dc:creator>Derek Martin</dc:creator>
		<pubDate>Fri, 29 Jul 2011 01:11:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.chrisdanielson.com/?p=275#comment-554</guid>
		<description>I implemented it as a View Helper, so in my xml view I can do $this-&gt;xml($this-&gt;content); and in my json view I can do: $this-&gt;json($this-&gt;content); I got the idea from an article by Matthew Weier O&#039;Phinney, at: http://weierophinney.net/matthew/archives/233-Responding-to-Different-Content-Types-in-RESTful-ZF-Apps.html</description>
		<content:encoded><![CDATA[<p>I implemented it as a View Helper, so in my xml view I can do $this->xml($this->content); and in my json view I can do: $this->json($this->content); I got the idea from an article by Matthew Weier O&#8217;Phinney, at: <a href="http://weierophinney.net/matthew/archives/233-Responding-to-Different-Content-Types-in-RESTful-ZF-Apps.html" rel="nofollow">http://weierophinney.net/matthew/archives/233-Responding-to-Different-Content-Types-in-RESTful-ZF-Apps.html</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Fabian</title>
		<link>http://www.chrisdanielson.com/2009/10/12/zend-restful-xml-generic-functions/comment-page-1/#comment-473</link>
		<dc:creator>Fabian</dc:creator>
		<pubDate>Thu, 11 Nov 2010 21:35:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.chrisdanielson.com/?p=275#comment-473</guid>
		<description>Hi,

one year past by since you wrote this.
I have a better idea (which I didn&#039;t tested yet): Zend_Rest_Controller just extends Zend_Controller_Action, so you can have action helpers. If you create an action helper which is parsing your arrays/objects to XML/JSON you don&#039;t need to extend Zend_Rest_Controller, avoid static methods, pass the output direct to the response object without having view scripts and have a nice and clean solution.</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>one year past by since you wrote this.<br />
I have a better idea (which I didn&#8217;t tested yet): Zend_Rest_Controller just extends Zend_Controller_Action, so you can have action helpers. If you create an action helper which is parsing your arrays/objects to XML/JSON you don&#8217;t need to extend Zend_Rest_Controller, avoid static methods, pass the output direct to the response object without having view scripts and have a nice and clean solution.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris Danielson</title>
		<link>http://www.chrisdanielson.com/2009/10/12/zend-restful-xml-generic-functions/comment-page-1/#comment-153</link>
		<dc:creator>Chris Danielson</dc:creator>
		<pubDate>Sat, 28 Nov 2009 21:36:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.chrisdanielson.com/?p=275#comment-153</guid>
		<description>Charles,
My apologies for the delay.  I was on vacation with my family.  This looks great!  I went ahead and put everything into a code highlighted block!  Thanks for sharing.
Regards,
Chris</description>
		<content:encoded><![CDATA[<p>Charles,<br />
My apologies for the delay.  I was on vacation with my family.  This looks great!  I went ahead and put everything into a code highlighted block!  Thanks for sharing.<br />
Regards,<br />
Chris</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Charles</title>
		<link>http://www.chrisdanielson.com/2009/10/12/zend-restful-xml-generic-functions/comment-page-1/#comment-151</link>
		<dc:creator>Charles</dc:creator>
		<pubDate>Wed, 25 Nov 2009 05:19:47 +0000</pubDate>
		<guid isPermaLink="false">http://www.chrisdanielson.com/?p=275#comment-151</guid>
		<description>Hi Chris-

I was having some problems getting arrays and objects to convert to XML. I made a few changes to your posted code, and just wanted to share it. I also removed the runtime call-by-reference markers from the calls to the _xmlHelper method,  as this feature has been deprecated, and results in a warning depending on the error reporting level. Here&#039;s the code, my apologies if I&#039;m violating comment ettiquette by listing it out here:
&lt;pre lang=&quot;php&quot; colla=&quot;+&quot;&gt;
public static function getXML($obj)
    {
        $doc = new DOMDocument();
        $doc-&gt;formatOutput = true;
        $root_element = $doc-&gt;createElement(&quot;response&quot;);
        $doc-&gt;appendChild($root_element);

        foreach($obj as $var =&gt; $value)
        {
            $statusElement = $doc-&gt;createElement($var);
            if (!is_array($value) &amp;&amp; !is_object($value))
            {
                $statusElement-&gt;appendChild($doc-&gt;createTextNode($value));
                $root_element-&gt;appendChild($statusElement);
            }
            else
            {
                self::_xmlHelper($doc, $root_element, $statusElement, $value);
            }
        }
        print $doc-&gt;saveXML();
    }

    public static function _xmlHelper(&amp;$doc, &amp;$root_element, &amp;$statusElement, &amp;$value)
    {
        if (is_array($value))
        {
            foreach ($value as $key =&gt; $val)
            {
                if (is_array($val))
                {
                    self::_xmlHelper($doc, $root_element, $statusElement, $val);
                }
                else if (is_object($val))
                {
                        $se = $doc-&gt;createElement(str_replace(&#039;object&#039;,&#039;&#039;,get_class($val)));
                        $arr = get_object_vars($val);
                        self::_xmlHelper($doc, $root_element, $se, $arr);
                        $root_element-&gt;appendChild($se);

                }
                else
                {
                    //print $key . &quot; =&gt; &quot; . $val . &quot;\n&quot;;
                        $se = $doc-&gt;createElement($key);
                        $se-&gt;appendChild($doc-&gt;createTextNode($val));
                        $statusElement-&gt;appendChild($se);

                }
            }
        $root_element-&gt;appendChild($statusElement);
        //print_r($value);
        }
        else if (is_object($value))
        {
                $se = $doc-&gt;createElement(str_replace(&#039;object&#039;,&#039;&#039;,get_class($value)));
                $arr = get_object_vars($value);
                self::_xmlHelper($doc, $root_element, $se, $arr);
                $root_element-&gt;appendChild($se);
        }
        else
        {
                $statusElement-&gt;appendChild($doc-&gt;createTextNode($value));
                $root_element-&gt;appendChild($statusElement);
        }
    }
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>Hi Chris-</p>
<p>I was having some problems getting arrays and objects to convert to XML. I made a few changes to your posted code, and just wanted to share it. I also removed the runtime call-by-reference markers from the calls to the _xmlHelper method,  as this feature has been deprecated, and results in a warning depending on the error reporting level. Here&#8217;s the code, my apologies if I&#8217;m violating comment ettiquette by listing it out here:</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p275code1'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p2751"><td class="code" id="p275code1"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> static <span style="color: #000000; font-weight: bold;">function</span> getXML<span style="color: #009900;">&#40;</span><span style="color: #000088;">$obj</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$doc</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> DOMDocument<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$doc</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">formatOutput</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$root_element</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$doc</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;response&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$doc</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">appendChild</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$root_element</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$obj</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$var</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$statusElement</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$doc</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$var</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><a href="http://www.php.net/is_array"><span style="color: #990000;">is_array</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span><a href="http://www.php.net/is_object"><span style="color: #990000;">is_object</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$statusElement</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">appendChild</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$doc</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">createTextNode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #000088;">$root_element</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">appendChild</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$statusElement</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #b1b100;">else</span>
            <span style="color: #009900;">&#123;</span>
                <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span>_xmlHelper<span style="color: #009900;">&#40;</span><span style="color: #000088;">$doc</span><span style="color: #339933;">,</span> <span style="color: #000088;">$root_element</span><span style="color: #339933;">,</span> <span style="color: #000088;">$statusElement</span><span style="color: #339933;">,</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">print</span> <span style="color: #000088;">$doc</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">saveXML</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> static <span style="color: #000000; font-weight: bold;">function</span> _xmlHelper<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span><span style="color: #000088;">$doc</span><span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span><span style="color: #000088;">$root_element</span><span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span><span style="color: #000088;">$statusElement</span><span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/is_array"><span style="color: #990000;">is_array</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$val</span><span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
                <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/is_array"><span style="color: #990000;">is_array</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$val</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
                <span style="color: #009900;">&#123;</span>
                    <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span>_xmlHelper<span style="color: #009900;">&#40;</span><span style="color: #000088;">$doc</span><span style="color: #339933;">,</span> <span style="color: #000088;">$root_element</span><span style="color: #339933;">,</span> <span style="color: #000088;">$statusElement</span><span style="color: #339933;">,</span> <span style="color: #000088;">$val</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
                <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/is_object"><span style="color: #990000;">is_object</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$val</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
                <span style="color: #009900;">&#123;</span>
                        <span style="color: #000088;">$se</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$doc</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">createElement</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/str_replace"><span style="color: #990000;">str_replace</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'object'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">''</span><span style="color: #339933;">,</span><a href="http://www.php.net/get_class"><span style="color: #990000;">get_class</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$val</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        <span style="color: #000088;">$arr</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/get_object_vars"><span style="color: #990000;">get_object_vars</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$val</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span>_xmlHelper<span style="color: #009900;">&#40;</span><span style="color: #000088;">$doc</span><span style="color: #339933;">,</span> <span style="color: #000088;">$root_element</span><span style="color: #339933;">,</span> <span style="color: #000088;">$se</span><span style="color: #339933;">,</span> <span style="color: #000088;">$arr</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        <span style="color: #000088;">$root_element</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">appendChild</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$se</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
                <span style="color: #009900;">&#125;</span>
                <span style="color: #b1b100;">else</span>
                <span style="color: #009900;">&#123;</span>
                    <span style="color: #666666; font-style: italic;">//print $key . &quot; =&gt; &quot; . $val . &quot;\n&quot;;</span>
                        <span style="color: #000088;">$se</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$doc</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        <span style="color: #000088;">$se</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">appendChild</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$doc</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">createTextNode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$val</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        <span style="color: #000088;">$statusElement</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">appendChild</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$se</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #000088;">$root_element</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">appendChild</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$statusElement</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">//print_r($value);</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/is_object"><span style="color: #990000;">is_object</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$se</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$doc</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">createElement</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/str_replace"><span style="color: #990000;">str_replace</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'object'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">''</span><span style="color: #339933;">,</span><a href="http://www.php.net/get_class"><span style="color: #990000;">get_class</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #000088;">$arr</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/get_object_vars"><span style="color: #990000;">get_object_vars</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span>_xmlHelper<span style="color: #009900;">&#40;</span><span style="color: #000088;">$doc</span><span style="color: #339933;">,</span> <span style="color: #000088;">$root_element</span><span style="color: #339933;">,</span> <span style="color: #000088;">$se</span><span style="color: #339933;">,</span> <span style="color: #000088;">$arr</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #000088;">$root_element</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">appendChild</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$se</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">else</span>
        <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$statusElement</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">appendChild</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$doc</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">createTextNode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #000088;">$root_element</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">appendChild</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$statusElement</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
	</item>
</channel>
</rss>

