xml in response not well formed

165 views
Skip to first unread message

Martin

unread,
Sep 25, 2011, 5:38:42 PM9/25/11
to web2py-users
Hello All, sorry for the bother I am having an issue with Version
1.99.1 (2011-09-22 16:59:24) stable release. It seems to be that there
are some problems when parsing the .xml view file, not sure. I have a
function (device_cfg) in controllers/default.py, which performs some
processing and pass to the view the following
dictionary:

return dict(operation=operation, op_response=op_response)

with:
operation = "get_leafs"
op_response = "True"

The following code is the view (device_cfg.xml):

<?xml version="1.0" encoding="UTF-8"?>
{{if operation == 'get_containers':}}
{{parent_id = op_response['parent_id']}}
{{childs_list = op_response['childs_list']}}
<root>
{{for node in childs_list:}}
<item id="{{=node[0]}}" parent_id="{{=parent_id}}"
state="closed">
<content>
<name><![CDATA[{{=node[1]}}]]></name>
</content>
</item>
{{pass}}
</root>
{{pass}}

{{if operation == 'get_leafs':}}
{{limit = op_response['limit']}}
{{parent_id = op_response['parent_id']}}
{{childs_list = op_response['childs_list']}}
{{page = op_response['page']}}
{{start = op_response['start']}}
{{iter = op_response['iter']}}
{{total_pages = op_response['total_pages']}}

<rows>
<page>{{ =page }}</page>
<total>{{ =total_pages }}</total>
<records>{{ =len(childs_list) }}</records>
{{for i in iter:}}
{{node = childs_list[i]}}
<row id = '{{=node[0]}}'>
<cell>{{=node[0]}}</cell>
<cell>{{=node[1]}}</cell>
<cell>{{=node[2]}}</cell>
</row>
{{pass}}
</rows>
{{pass}}

{{if operation == 'leaf_remove':}}
<result>{{=op_response}}</result>
{{pass}}

{{if operation == 'leaf_create':}}
<result>{{=op_response}}</result>
{{pass}}

{{if operation == 'leaf_modify':}}
<result>{{=op_response}}</result>
{{pass}}

{{if operation == 'container_remove':}}
<result>{{=op_response}}</result>
{{pass}}

{{if operation == 'container_create':}}
<result>{{=op_response}}</result>
{{pass}}

{{if operation == 'container_edit':}}
<result>{{=op_response}}</result>
{{pass}}

{{if operation == 'validate_commit':}}
<response>
<result>{{=op_response[0]}}</result>
<feedback>{{=op_response[1]}}</feedback>
</response>
{{pass}}

{{if operation == 'validate_commit_cancel':}}
<result>{{=op_response}}</result>
{{pass}}

{{if operation == 'get_ns_map':}}
<rows>
<page>{{=1}}</page>
<total>{{=1}}</total>
<records>{{=len(op_response)}} </records>
{{i=0}}
{{for ns in op_response:}}
<row id="{{=i}}">
<cell>{{=ns}}</cell>
<cell><![CDATA["{{=op_response[ns]}}"]]></cell>
</row>
{{i += 1}}
{{pass}}
</rows>
{{pass}}

{{if operation == 'push_config':}}
<response>
<result>{{=op_response[0]}}</result>
<feedback>{{=op_response[1]}}</feedback>
</response>
{{pass}}


The expected replied xml is:

<?xml version="1.0" encoding="UTF-8"?>
<result>True</result>

But it returns:

<?xml version="1.0" encoding="UTF-8"?>
<result>True</result>
<total>1.0</total>
<records>2</records>
<row id = '2'>
<cell>2</cell>
<cell>ns1:max-lease-time</cell>
<cell>asds</cell>
</row>
<row id = '3'>
<cell>3</cell>
<cell>ns1:default-lease-time</cell>
<cell>600</cell>
</row>
</rows>

Firefox is complaining with the following error code: "XML Parsing
Error: junk after document element Location: moz-nullprincipal:
{c9878540-af47-407f-b97b-4709a9fcecdf} Line Number 26, Column 3:
<total>1.0</total>".

I have checked the view several times and I am not able to figure out
what is going on. Could someone please help me?...

Any help will be appreciated!

Regards,
Tincho

Martin

unread,
Sep 25, 2011, 5:41:56 PM9/25/11
to web2py-users
I appologize: the variables passed to the view are:

operation = "leaf_modify"
op_response = "True"

Tincho

Jonathan Lundell

unread,
Sep 25, 2011, 6:00:49 PM9/25/11
to web...@googlegroups.com
FWIW, it looks to me like the extra lines are left over from a previous response (or something like that) and not being generated by this particular invocation of the view.

Why that would happen I have no idea.

Martin

unread,
Sep 25, 2011, 6:52:51 PM9/25/11
to web2py-users
yes, you are right, because the variables for the following xml part
it suppose to be not available for current request, which corresponds
to operation == 'get_leafs'...

Jonathan Lundell

unread,
Sep 25, 2011, 6:54:40 PM9/25/11
to web...@googlegroups.com
On Sep 25, 2011, at 3:52 PM, Martin wrote:

> yes, you are right, because the variables for the following xml part
> it suppose to be not available for current request, which corresponds
> to operation == 'get_leafs'...

Can you get a look at the Content-length header of the response?

Martin

unread,
Sep 25, 2011, 7:32:00 PM9/25/11
to web2py-users
Response Headers
X-Powered-By web2py
Set-Cookie session_id_nems_web=127.0.0.1-1c024dc8-7db7-440c-a45e-
d57de93d8879; Path=/
Expires Sun, 25 Sep 2011 23:30:33 GMT
Pragma no-cache
Cache-Control no-store, no-cache, must-revalidate, post-check=0, pre-
check=0
Content-Type application/xml
Date Sun, 25 Sep 2011 23:30:33 GMT
Server Rocket 1.2.4 Python/2.7.1+
Content-Length 85
Connection keep-alive

Jonathan Lundell

unread,
Sep 25, 2011, 7:40:46 PM9/25/11
to web...@googlegroups.com

Well, that's interesting. There are certainly more than 85 characters in the content you originally quoted. It might be worth trying another browser, if you can.

Martin

unread,
Sep 25, 2011, 7:52:10 PM9/25/11
to web2py-users
I tested with Chrome and I don't have the issue... so, it seems to be
that it's in the Firefox side... this is really weird...

Thank you very much for your help Jonathan, I will include a
restriction to open the application just with Chrome...

Much appreciated!

Martin
Reply all
Reply to author
Forward
0 new messages