Hello
I try to generate XML-file as output report by script.
I write some code:
function writeXml(xmlOutput, xmlParent, oItem, sElement) {
var xmlItem = xmlOutput.addElement(xmlParent, sElement);
xmlItem.setAttribute("Attr1", oItem.Att1);
xmlItem.setAttribute("Attr2", oItem.Att2);
return xmlItem;
}
function main() {
var aItem = new Array();
aItem.push({Att1:"x1", Att2:"y1"});
aItem.push({Att1:"x11", Att2:"y11"});
aItem.push({Att1:"x12", Att2:"y12"});
var xmlOutput = Context.createXMLOutputObject(Context.getSelectedFile(), "Root");
var xmlItem1 = writeXml(xmlOutput, xmlOutput.getRootElement(), aItem[0], "Item1");
var xmlItem11 = writeXml(xmlOutput, xmlItem1, aItem[1], "Item11");
var xmlItem12 = writeXml(xmlOutput, xmlItem1, aItem[2], "Item12");
xmlOutput.WriteReport();
}
main();After launching this script I get XML-file:
<?xml version="1.0" encoding="UTF-8"?>
<Root>
<Item1 Attr2="y1" Attr1="x1">
<Item11 Attr2="y11" Attr1="x11"/>
<Item12 Attr2="y12" Attr1="x12"/>
</Item1>
</Root>Tell me please, how can I generate XML-file with structure like this:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:aris="http://test.ru/portal/aris">
<soapenv:Header/>
<soapenv:Body>
<aris:arisUrlRequest>
<ATTR1>?</ATTR1>
<ATTR2>?</ATTR2>
</aris:arisUrlRequest>
</soapenv:Body>
</soapenv:Envelope>
Kay Fischbach on
Hi
if it's just recreating that "XML-file with structure like this", that's not that hard.
This should do the trick:
It generates:
You may notice that it doesn't use that many methods of the ARIS XMLOutputWriter. That's because the part of jdom that ARIS exposes to us is quite limiting. Instead of accepting those limitations you simply have to retrieve the root jdom element from the writer and configure your document with that to your liking using the jdom Java methods.
For me the jdom version ARIS had built in was version 1.1.3 (quite an old version considering jdom 2 is around for more than 5 years already). If you're able to you should look into the files on your server to figure out which jdom version is used.
I used the jdom documentation found here for version 1.1.3: http://www.jdom.org/docs/apidocs.1.1/
Hope this helps and good luck with integrating your aItem elements into your xml.