AI

Hi everyone,

I couldn't find answers to this question on the forum, so I will post it as new one.

I am working on a script in ARIS and I have a structure in a string variable that I want to print in file.

I want to be .xml file that will contain the structure that is stored in the variable.

How can I do this?

Many thanks

by Kay Fischbach
Posted on Fri, 01/11/2019 - 08:25

Could you give an example string, (doesn't need to be filled with real data, just replace any real data with fake/test data).

How I would go about this:

  1. split the string variable with regex into separate strings
  2. You can use the following method to create a new XML Output object (if you set XML as the output object of your report)
var p_Output = Context.createXMLOutputObject(Context.getSelectedFile(), "testRoot");

Where

  • "Context.getSelectedFile()" retrieves the file name of the file set with the report-execution wizard. If you want the XML file in addition to another file, you would just put a string with the file name here (e.g. "additionalXML.xml". Note: you would have to add the file to the outputFiles in order to transfer them to the client after the report execution. Read further down below more about it.). If you specify your own file name here, the output format specified with the wizard can be anything.
  • "testRoot" is the name of the root element in your XML. This can be any name - since you are interested in getting the result as an XML I assume you know how XML works.

After creating the output object you can start adding elements to it.

Basic child Nodes would be added with

var childElement = p_Output.addElement(p_Output.getRootElement(), "TestChild");

where

  • the first parameter specifies the parent Element (in this case the root Element)
  • the second parameter specifies the element name of the newly created XML node

Note that the "addElement" method directly returns the newly created element-object, so you can assign the return value to a variable to use it later (like I did with "childElement").

You can put the "addElement" method-call into a loop to iterate through your ARIS objects and create as many elements as you have ARIS objects.

To set the xml-element attribute values that you got from splitting the ARIS-attribute-value with regex, you can use

childElement.setAttribute("testAttribute", "testAttributeValue");

where

  • "childElement" is the element you previously created
  • "testAttribute" is the attribute name
  • "testAttributeValue" is the value that you want to assign to the attribute

 

ARIS-script uses an implementation of JDOM, so if you want to know what else you can do with elements, take a look at http://www.jdom.org/docs/apidocs/ and in the lower left panel select "Element" to get a list of methods you can use with objects of the type "Element" in the right panel.

After you are done with everything, write the data to the file with

p_Output.WriteReport();

Note: if you created a new file for the xml-file, you'll have to add it to the files to transfer to the client, after writing the data to the file. Do so by using

Context.addOutputFileName("additionalXML.xml");

where

  • "additionalXML.xml" is the name of the file you specified when creating the XmlOutput object

If you don't use the "addOutputFileName" method, the file would never be transferred to the client and subsequently it would not open after the report is done with the execution. If you used "Context.getSelectedFile()" when creating the object you do NOT have to use the addOutputFileName method - the selected file is part of the files to transfer to the client by default.

0
by Alokin Iksok Author
Posted on Tue, 01/15/2019 - 10:09

Thank you for your answer!

The thing is that I have already done in my script the attributes, childs etc.. and I just need a plain .xml file that will accept for example this structure to print:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="note">

  <xs:complexType>

    <xs:sequence>

      <xs:element name="to" type="xs:string"/>

      <xs:element name="from" type="xs:string"/>

      <xs:element name="heading" type="xs:string"/>

      <xs:element name="body" type="xs:string"/>

    </xs:sequence>

  </xs:complexType>

</xs:element>

</xs:schema>

So, just to create empty .xml file and then send a string to print there.

0
by Kay Fischbach
Posted on Tue, 01/15/2019 - 12:42

In reply to by calokin

Uh, you could have said that before.

So you would want to do something like this:

var nLocale = Context.getSelectedLanguage();

var p_Output = Context.createOutputObject(Constants.OutputXML, Context.getSelectedFile());
var attrValue = ArisData.getSelectedObjOccs()[0].ObjDef().Attribute(Constants.AT_DESC, nLocale).getValue();
p_Output.OutputLn(attrValue, "Arial", 11, Constants.C_BLACK, Constants.C_TRANSPARENT, Constants.FMT_LEFT, 0);

p_Output.WriteReport();

 

 

0
by Alokin Iksok Author
Posted on Tue, 01/15/2019 - 16:18

In reply to by Kay Fischbach

Thanks for the answer!

But instead of Context.getSelectedFile(), can I use variable?

For an example, variable

var sString = "<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="note">

  <xs:complexType>

    <xs:sequence>

      <xs:element name="to" type="xs:string"/>

      <xs:element name="from" type="xs:string"/>

      <xs:element name="heading" type="xs:string"/>

      <xs:element name="body" type="xs:string"/>

    </xs:sequence>

  </xs:complexType>

</xs:element>

</xs:schema>";

So I get an error for invalid file name.

0
by Kay Fischbach
Posted on Wed, 01/16/2019 - 08:35

In reply to by calokin

Context.getSelectedFile() is just the file name of the file that will be outputted in the end (this specific file name is determined with the report wizard when you start the report.). It could also be a variable with the value "result.xml", "reportResult.xml",... . You wouldn't want to put the file content there, would you?

Putting your string directly into the script is a bit tricky, because it contains quotation marks - which usually start and end a string in Javascript. You can't just put quotation marks at the start and end of your string - there are quotation marks in between the start and end of the string, how is the computer supposed to tell your quotation marks and the quotation marks in your string apart? You would have to put a backslash (\) in front of every quotation mark inside your string, to signal to the computer that this should not be treated as a string-ending quotation mark.

In addition to that Javascript is multi-line sensitive, meaning line breaks matter and the line breaks in your script are cancer for the computer. You would have to put each line in quotation marks, and connect them with the plus symbol (+), and add a \n at the end of each line, to mark them as one string with multiple lines. You could also write everything in one line, and instead of line breaks just use \n (no space before or after \n needed).

If you still insist on just wanting to print this static xml content into a file, try this:

var nLocale = Context.getSelectedLanguage();

var p_Output = Context.createOutputObject(Constants.OutputXML, Context.getSelectedFile());
var attrValue = "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema(link is external)\">\n" +
" <xs:element name=\"note\">\n" +
"   <xs:complexType>\n" +
"     <xs:sequence>\n" +
"       <xs:element name=\"to\" type=\"xs:string\"/>\n" +
"       <xs:element name=\"from\" type=\"xs:string\"/>\n" +
"       <xs:element name=\"heading\" type=\"xs:string\"/>\n" +
"       <xs:element name=\"body\" type=\"xs:string\"/>\n" +
"     </xs:sequence>\n" +
"   </xs:complexType>\n" +
" </xs:element>\n" +
" </xs:schema>\n";
p_Output.OutputLn(attrValue, "Arial", 11, Constants.C_BLACK, Constants.C_TRANSPARENT, Constants.FMT_LEFT, 0);

p_Output.WriteReport();

 

It would be much easier to store the string as an attribute value in an ARIS object, and just reading it from there with the method described in my previous comment. You would not need to worry about escape characters, line breaks and holding everything together.

0

Featured achievement

Rookie
Say hello to the ARIS Community! Personalize your community experience by following forums or tags, liking a post or uploading a profile picture.
Recent Unlocks

Leaderboard

|
icon-arrow-down icon-arrow-cerulean-left icon-arrow-cerulean-right icon-arrow-down icon-arrow-left icon-arrow-right icon-arrow icon-back icon-close icon-comments icon-correct-answer icon-tick icon-download icon-facebook icon-flag icon-google-plus icon-hamburger icon-in icon-info icon-instagram icon-login-true icon-login icon-mail-notification icon-mail icon-mortarboard icon-newsletter icon-notification icon-pinterest icon-plus icon-rss icon-search icon-share icon-shield icon-snapchat icon-star icon-tutorials icon-twitter icon-universities icon-videos icon-views icon-whatsapp icon-xing icon-youtube icon-jobs icon-heart icon-heart2 aris-express bpm-glossary help-intro help-design Process_Mining_Icon help-publishing help-administration help-dashboarding help-archive help-risk icon-knowledge icon-question icon-events icon-message icon-more icon-pencil forum-icon icon-lock