如何使用kettle的js腳本建立xml資料
項目上遇到需求需要在kettle手動生成一段下xml資料,想到可以使用kettle中的js腳本元件去生成,但是如果使用字元串拼接的方法生成xml會非常麻煩,這裡分享一個簡單的方法:
首先 var request = new XML();
然後就可以之間給request指派xml的内容了。
var request = new XML();
request=<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:sap-com:document:sap:soap:functions:mc-style">
<soapenv:Header/>
<soapenv:Body>
<urn:ZrfcGetBwdata>
<!--Optional:-->
<ItFields>
<!--Zero or more repetitions:-->
</ItFields>
<!--Optional:-->
<ItOptions>
<!--Zero or more repetitions:-->
<item>
<Text></Text>
</item>
</ItOptions>
</urn:ZrfcGetBwdata>
</soapenv:Body>
</soapenv:Envelope>;
var requsetXml=request.toXMLString();
那如果這個xml的内容需要從前一個步驟取值該怎麼做呢,可以使用{變量名}擷取。
如:
var request = new XML();
request=<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:sap-com:document:sap:soap:functions:mc-style">
<soapenv:Header/>
<soapenv:Body>
<urn:ZrfcGetBwdata>
<!--Optional:-->
<ItFields>
<!--Zero or more repetitions:-->
</ItFields>
<!--Optional:-->
<ItOptions>
<!--Zero or more repetitions:-->
<item>
<Text>{where}</Text>
</item>
</ItOptions>
</urn:ZrfcGetBwdata>
</soapenv:Body>
</soapenv:Envelope>;
var requsetXml=request.toXMLString();

這樣就可以取到值了。