[英]Python - how to extract a soap envelope from input xml and send as output
我是 python 的新手,我有一個輸入 xml,它在子節點下嵌入了一個 soap 信封。 輸入 xml:
<SyncShipmentCreation xmlns="http://schema.infor.com/InforOAGIS/2" releaseID="2">
<ApplicationArea>
<CreationDateTime>2022-06-22T14:21:56Z</CreationDateTime>
</ApplicationArea>
<DataArea>
<Sync>
<TenantID>TLD_TST</TenantID>
</Sync>
<ShipmentCreation>
<soapenv:Envelope xmlns:dns="http://schema.infor.com/InforOAGIS/2" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header>
</soapenv:Header>
<soapenv:Body>
<ShipmentRequest xmlns="http://xxxyyyzzz.com/ShipmentMsgRequest">
...
</ShipmentRequest>
</soapenv:Body>
</soapenv:Envelope>
</ShipmentCreation>
</DataArea>
</SyncShipmentCreation>
soap 部分是需要的 Output。 喜歡
<soapenv:Envelope xmlns:dns="http://schema.infor.com/InforOAGIS/2" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
..............
</soapenv:Envelope>
這可能嗎? 我找不到如何解析/提取此值並將其分配給 output 變量。 請幫忙。
其中一種方法是按以下方式使用 lxml 庫:
from lxml import etree
soap ="""[your xml above]"""
doc1 = etree.XML(soap)
#locate your target nodes and assign them to a second document
doc2 = doc1.xpath('//*[local-name()="ShipmentCreation"]/*')[0]
print(etree.tostring(doc2).decode())
output 應該是您預期的 output。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.