我希望使用lxml自动编写一个集合XML文件,因此我需要编写“xi:include”之类的内容:
...
<Time Type="Single" Value="2"/>
<xi:include href="elemData_2.xmf" xpointer="xpointer(//XDMF/Domain/Grid)"/>
<Time Type="Single" Value="3"/>
<xi:include href="elemData_3.xmf" xpointer="xpointer(//XDMF/Domain/Grid)"/>
<Time Type="Single" Value="4"/>
<xi:include href="elemData_4.xmf" xpointer="xpointer(//XDMF/Domain/Grid)"/>
...
似乎XInclude()仅用于解析并尝试附加名称的子元素:'xi:include'发出错误。所以我很感激帮助。我使用的代码:
xdmfItem.append(etree.SubElement(Grid, "xiinclude", {'href': 'elemData_'+str(ii+1)+'.xmf', 'xpointer':'xpointer(//XDMF/Domain/Grid)' }))
错误:
ValueError: Invalid tag name u'xi:include'
提前致谢 希沙姆
编辑:(如果我等了8个小时,我可能不会写答案)
谢谢你,你的指针帮我找到了解决方案:
xdmfItem.append(etree.SubElement(Grid, "{http://www.w3.org/2003/XInclude}include", {'href': 'elemData_'+str(ii+1)+'.xmf', 'xpointer':'xpointer(//XDMF/Domain/Grid)' }))