我正在尝试形成具有某些属性的xml请求。该属性还具有一些名称空间。有人可以帮助我使用正确的语法来形成正确的xml请求。
例如
Sample xml
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns1="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ns2="http://www.w3.org/2001/XMLSchema"
<soapenv:Header/>
<soapenv:Body>
<Request>
<soapenv:age ns1:type="ns2:string">1234</soapenv:age>
</Request>
</soapenv:Body>
</soapenv:Envelope>
dataweave
%dw 1.0
%output application/xml
{
ns1#age @(ns1#type: "ns2#string"): "1234"
}
%dw 1.0
%output application/xml encoding="utf-8"
%namespace soapenv http://schemas.xmlsoap.org/soap/envelope/
%namespace ns1 http://www.w3.org/2001/XMLSchema-instance
%namespace ns2 http://www.w3.org/2001/XMLSchema
---
soapenv#Envelope: {
soapenv#Header : {
soapenv#Body: {
Request: {
soapenv#age @(ns1#type: "ns2#string"): "1234"
}
}
}
}
输出:
<?xml version='1.0' encoding='utf-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header>
<soapenv:Body>
<Request>
<soapenv:age xmlns:ns1="http://www.w3.org/2001/XMLSchema-instance" ns1:type="ns2#string">1234</soapenv:age>
</Request>
</soapenv:Body>
</soapenv:Header>
</soapenv:Envelope>
请注意,转换未使用ns2,因此不会在输出中发出它。如果需要它出现,则需要向某个元素添加一个哑属性,并将元素ns2作为名称空间(例如@(ns2#dummy:'')
。