Invalid XML code generated by web service
<p>It seems like the <code>@service.xml</code> decorator is broken in <a href="http://web2py.com/books/default/chapter/29/10/services#Remote-procedure-calls" rel="nofollow">web services RPC</a>.</p>

<pre><code>@service.xml
def concat(a, b):
    return a + b
</code></pre>

<p>The result is:</p>

<pre><code>&gt;&gt;&gt; from urllib import urlopen
&gt;&gt;&gt; r = urlopen("http://127.0.0.1:8000/webservice/default/call/xml/concat/hello/
world")
&gt;&gt;&gt; r.read()
'&lt;?xml version="1.0" encoding="UTF-8"?&gt;helloworld'
</code></pre>

<p>The last part is missing which produces invalid XML.</p>

<p>However, JSON and CSV work well.</p>

<pre><code>@service.json
def concat(a, b):
    return a + b
</code></pre>

<p>Test:</p>

<pre><code>&gt;&gt;&gt; r = urlopen("http://127.0.0.1:8000/webservice/default/call/json/concat/hello
/world")
&gt;&gt;&gt; r.read()
'"helloworld"'
</code></pre>

<p>I'm testing this in a copy of the scaffolding application. Am I missing something or this is really an issue?</p>

<p>I think it is just a bad example in the book. To produce valid XML, the function should return a list or dictionary (or an object with a <code>.as_list</code>, <code>.as_dict</code>, or <code>.custom_xml</code> method). For example:</p>

<pre><code>@service.xml
def concat(a, b):
    return dict(result=a + b)
</code></pre>

<p>produces:</p>

<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;document&gt;
  &lt;result&gt;helloworld&lt;/result&gt;
&lt;/document&gt;
</code></pre>

python xml python-2.7 web-services web2py