如何在python中向genshi生成的XML节点添加CDATA

如何在python中向genshi生成的XML节点添加CDATA,python,xml,cdata,genshi,Python,Xml,Cdata,Genshi,我需要在使用Genshi和模板的python生成的XML节点中插入CDATA 在节点内部,我需要迭代products变量。在下面的模板中放置类似CDATA的迭代不会执行,错误“p”未定义 如何获取适当的xml文档以将其发送到soap服务器 Python代码 from genshi.template import MarkupTemplate tmpl = MarkupTemplate(template_str) xml = tmpl.generate(**datos).render(meth

我需要在使用Genshi和模板的python生成的XML节点中插入CDATA

在节点内部,我需要迭代products变量。在下面的模板中放置类似CDATA的迭代不会执行,错误
“p”未定义

如何获取适当的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>
模板

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>