1
是否可以使用lxml構造一個XML作爲這個XML?lxml - 具有多個名稱空間的XML文檔
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns0="http://xmlns.CLT.com/consume/ENTBUS" xmlns:ns1="http://xmlns.CLT.com/Core/ENTBUS" xmlns:ns2="http://xmlns.CLT.com/output/EBO">
<soapenv:Header/>
<soapenv:Body>
<ns0:ConsumptionRequestENTBUS>
<ns1:ENTBUSHeader>
<ns1:ENTBUSID>1</ns1:ENTBUSID>
</ns1:ENTBUSHeader>
<ns0:Zone>
<ns2:Consumption>
<ns2:BusCode>1</ns2:BusCode>
</ns2:Consumption>
</ns0:Zone>
</ns0:ConsumptionRequestENTBUS>
</soapenv:Body>
</soapenv:Envelope>
我試着構建如下的根元素,但失敗了。幾乎每個元素都需要被命名空間引用。
>>> from lxml import etree
>>> root = etree.Element("soapenv:Envelope")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "lxml.etree.pyx", line 2811, in lxml.etree.Element (src\lxml\lxml.etree.c:65389)
File "apihelpers.pxi", line 103, in lxml.etree._makeElement (src\lxml\lxml.etree.c:13898)
File "apihelpers.pxi", line 1575, in lxml.etree._tagValidOrRaise (src\lxml\lxml.etree.c:27955)
ValueError: Invalid tag name u'soapenv:Envelope'
感謝
肥皂盒遠沒有完成。我是usig jurko-suds,它無法映射命名空間。所以我想用這種方式來構建請求。是否有可能幫助我1到1的泡沫問題? – Guddu 2015-01-20 21:12:44