我有下面的XML,我试图用lxml.objectifypackage
<file>
<customers>
<customer>
<phone>
<type>home</type>
<number>555-555-5555</number>
</phone>
<phone>
<type>cell</type>
<number>999-999-9999</number>
</phone>
<phone>
<type>home</type>
<number>111-111-1111</number>
</phone>
</customer>
</customers>
</file>
我不知道如何多次创建phone元素。基本上,我有以下非工作代码:
^{pr2}$当然,它只在结果XML中输出电话信息的一部分。有人有什么想法吗?在
下面是一些使用objectify E-Factory构造XML的示例代码:
我已经在这里硬编码了,但是你可以转换成一个循环覆盖你的数据。这对你有用吗?在
您应该创建
objectify.Element
对象,并将它们添加为root.customers
的子对象。在例如,可以这样插入两个电话号码:
{3>在转换这些不必要的属性时使用cd3}。 有关
objectify.deannotate
的确切参数,请参见lxml's objectify documentation。在(如果您使用的是旧版本的lxml,它不包括
^{pr2}$cleanup_namespaces
关键字参数,请改为执行以下操作:)
相关问题 更多 >
编程相关推荐