如何解决如何在python中将CDATA添加到由genshi生成的XML节点
我需要在使用Genshi和模板的python生成的XML节点中插入CDATA。
在节点内部,我需要遍历product变量。不会将CDATA放置在迭代下面的模板中,因为错误"p" not defined
如何获取正确的xml文档以将其发送到soap服务器?
Python代码
from genshi.template import MarkupTemplate
tmpl = MarkupTemplate(template_str)
xml = tmpl.generate(**datos).render(method='xml',encoding="utf-8")
模板
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:py="http://genshi.edgewall.org/">
<soapenv:Header/>
<soapenv:Body>
<ws1:method>
<ws1:field1>${value1}</ws1:field1>
<ws1:field2>${value2}</ws1:field2>
<ws1:xmlval>
<![CDATA[
<?xml version = "1.0" encoding = "utf-8"?>
<order>
<Codorder>${order}</Codorder>
<lines>
<line py:for="p in products">
<code>${p.code}</code>
<units>${p.qty}</units>
</line>
</lines>
</order>
]]>
</ws1:xmlval>
</ws1:method>
</soapenv:Body>
</soapenv:Envelope>
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com(将#修改为@)