<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.appian.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Dynamic XML generation</title><link>https://community.appian.com/discussions/f/general/19475/dynamic-xml-generation</link><description>HI, 
 
 What is the best practice to generate XML dynamically ? 
 The source data is in the database.</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: Dynamic XML generation</title><link>https://community.appian.com/thread/76174?ContentTypeID=1</link><pubDate>Fri, 28 Aug 2020 08:24:49 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:21b64b17-bced-4a08-96c8-1ca228a3402a</guid><dc:creator>Stewart Burchell</dc:creator><description>&lt;p&gt;It won&amp;#39;t be elegant but you could assemble the message&amp;nbsp;by providing a template of the message with a set of &amp;#39;tokens&amp;#39; embedded in it that you want to be substituted with the values from your database. I don&amp;#39;t know what the data looks like when you&amp;#39;ve retrieved it from the database but if you can coerce it into the format that I use in the following example this is how I would approach it:&lt;/p&gt;
&lt;p&gt;Here&amp;#39;s the XML message as a template with just the first 3 data items set as tags:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;utf-8&amp;quot;?&amp;gt;&amp;lt;BaExchReq xmlns:xc=&amp;quot;&amp;quot;&amp;gt; 
&amp;lt;Envelope&amp;gt; &amp;lt;TransactionRef&amp;gt;###TransactionRef###&amp;lt;/TransactionRef&amp;gt; 
 &amp;lt;MsgId&amp;gt;###MsgId###&amp;lt;/MsgId&amp;gt; 
 &amp;lt;CreationTime&amp;gt;###CreationTime###&amp;lt;/CreationTime&amp;gt; 
 &amp;lt;Requestor&amp;gt;##&amp;lt;/Requestor&amp;gt;
 &amp;lt;Responder&amp;gt;c##&amp;lt;/Responder&amp;gt; 
 &amp;lt;Service&amp;gt;##&amp;lt;/Service&amp;gt; 
 &amp;lt;RequestType&amp;gt;##&amp;lt;/RequestType&amp;gt; 
&amp;lt;/Envelope&amp;gt; 
&amp;lt;Payload&amp;gt; 
 &amp;lt;AppHdr xmlns=&amp;quot;&amp;quot;&amp;gt; 
  &amp;lt;MsgRef&amp;gt;##&amp;lt;/MsgRef&amp;gt; 
  &amp;lt;CrDate&amp;gt;##&amp;lt;/CrDate&amp;gt; 
 &amp;lt;/AppHdr&amp;gt; 
 &amp;lt;Document xmlns=&amp;quot;##&amp;quot;&amp;gt; 
  &amp;lt;SbcptOrdrV03&amp;gt; 
   &amp;lt;MsgId&amp;gt; 
    &amp;lt;Id&amp;gt;##&amp;lt;/Id&amp;gt; 
    &amp;lt;CreDtTm&amp;gt;##&amp;lt;/CreDtTm&amp;gt; 
   &amp;lt;/MsgId&amp;gt; 
   &amp;lt;MltplOrdrDtls&amp;gt; 
    &amp;lt;InvstmtAcctDtls&amp;gt; 
     &amp;lt;AcctId&amp;gt; 
      &amp;lt;Prtry&amp;gt; &amp;lt;Id&amp;gt;##&amp;lt;/Id&amp;gt; &amp;lt;/Prtry&amp;gt; 
     &amp;lt;/AcctId&amp;gt; 
    &amp;lt;/InvstmtAcctDtls&amp;gt; 
    &amp;lt;IndvOrdrDtls&amp;gt; 
     &amp;lt;OrdrRef&amp;gt;##&amp;lt;/OrdrRef&amp;gt; 
      &amp;lt;FinInstrmDtls&amp;gt; 
       &amp;lt;Id&amp;gt; 
        &amp;lt;ISIN&amp;gt;##&amp;lt;/ISIN&amp;gt;     
       &amp;lt;/Id&amp;gt;  
      &amp;lt;/FinInstrmDtls&amp;gt; 
      &amp;lt;GrssAmt Ccy=&amp;quot;&amp;quot;&amp;gt;##&amp;lt;/GrssAmt&amp;gt;
      &amp;lt;PhysDlvryInd&amp;gt;##&amp;lt;/PhysDlvryInd&amp;gt; 
      &amp;lt;ReqdSttlmCcy&amp;gt;##&amp;lt;/ReqdSttlmCcy&amp;gt;
    &amp;lt;/IndvOrdrDtls&amp;gt; 
   &amp;lt;/MltplOrdrDtls&amp;gt; 
  &amp;lt;/SbcptOrdrV03&amp;gt; 
 &amp;lt;/Document&amp;gt; 
&amp;lt;/Payload&amp;gt; 
&amp;lt;/BaExchReq&amp;gt;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;And here&amp;#39;s the code that takes that template a substitutes the tags for the corresponding values:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;a!localVariables(
  local!parameters: {
    {tag: &amp;quot;###TransactionRef###&amp;quot;, value: &amp;quot;ABC123&amp;quot;},
    {tag: &amp;quot;###MsgId###&amp;quot;, value: &amp;quot;123a4fc4g4aa1204&amp;quot;},
    {tag: &amp;quot;###CreationTime###&amp;quot;, value: &amp;quot;28-08-2020 09:03&amp;quot;}
  },
  fn!reduce(
    fn!substitute(
      _,
      _
    ),
    ri!xmlTemplate,
    fn!merge(
      fn!index(local!parameters,&amp;quot;tag&amp;quot;),
      fn!index(local!parameters,&amp;quot;value&amp;quot;)
    )
  )
)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;fn!reduce() is a loop that starts with an initial value - the template - and, for a provided list, runs a function - in this case fn!substitute -&amp;nbsp; on that value and then takes the result and passes that to the next iteration of the provided function.&lt;/p&gt;
&lt;p&gt;fn!merge() takes a set of lists and makes a list of those lists - in this case, takes the list of tags and list of values and pairs them up.&lt;/p&gt;
&lt;p&gt;The underscore is a way of &amp;#39;deferring&amp;#39; the actual value to be passed to run-time and maps the inputs to fn!substitute() to the items that follow in fn!reduce() in the order they appear.&lt;/p&gt;
&lt;p&gt;I know: it&amp;#39;s not intuitive but it is effective.&lt;/p&gt;
&lt;p&gt;Note: I am assuming that the example you&amp;#39;ve provided to me is &amp;#39;static&amp;#39; - that is, there are not any repeating elements, although the name &amp;#39;MltplOrdrDtls&amp;#39; does suggest there may be repeating elements within it, which will be a different challenge.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Dynamic XML generation</title><link>https://community.appian.com/thread/76172?ContentTypeID=1</link><pubDate>Fri, 28 Aug 2020 07:36:38 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:040d2fa6-b526-44e4-8067-a055158df486</guid><dc:creator>pooja.sudarshan</dc:creator><description>&lt;p&gt;&lt;a href="/members/stewart.burchell"&gt;Stewart Burchell&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Thank for your reply. Please find below details :&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Use Case : To generate XML dynamically from data in database.&lt;/p&gt;
&lt;p&gt;XML Format : Plese refere belw schema&lt;/p&gt;
&lt;p&gt;What is going to be consuming data : A variable which will be used to send this on MQ&lt;/p&gt;
&lt;p&gt;There is a parent child tags and few levels of casting . We have already tried using toXML() and it would need around 10-15 CDTs.&lt;/p&gt;
&lt;p&gt;Can we have another way to creae it?&lt;/p&gt;
&lt;p&gt;Below is the sample schema :&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="xml"&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;utf-8&amp;quot;?&amp;gt;&amp;lt;BaExchReq xmlns:xc=&amp;quot;&amp;quot;&amp;gt; 
&amp;lt;Envelope&amp;gt; &amp;lt;TransactionRef&amp;gt;##&amp;lt;/TransactionRef&amp;gt; 
 &amp;lt;MsgId&amp;gt;##&amp;lt;/MsgId&amp;gt; 
 &amp;lt;CreationTime&amp;gt;##&amp;lt;/CreationTime&amp;gt; 
 &amp;lt;Requestor&amp;gt;##&amp;lt;/Requestor&amp;gt;
 &amp;lt;Responder&amp;gt;c##&amp;lt;/Responder&amp;gt; 
 &amp;lt;Service&amp;gt;##&amp;lt;/Service&amp;gt; 
 &amp;lt;RequestType&amp;gt;##&amp;lt;/RequestType&amp;gt; 
&amp;lt;/Envelope&amp;gt; 
&amp;lt;Payload&amp;gt; 
 &amp;lt;AppHdr xmlns=&amp;quot;&amp;quot;&amp;gt; 
  &amp;lt;MsgRef&amp;gt;##&amp;lt;/MsgRef&amp;gt; 
  &amp;lt;CrDate&amp;gt;##&amp;lt;/CrDate&amp;gt; 
 &amp;lt;/AppHdr&amp;gt; 
 &amp;lt;Document xmlns=&amp;quot;##&amp;quot;&amp;gt; 
  &amp;lt;SbcptOrdrV03&amp;gt; 
   &amp;lt;MsgId&amp;gt; 
    &amp;lt;Id&amp;gt;##&amp;lt;/Id&amp;gt; 
    &amp;lt;CreDtTm&amp;gt;##&amp;lt;/CreDtTm&amp;gt; 
   &amp;lt;/MsgId&amp;gt; 
   &amp;lt;MltplOrdrDtls&amp;gt; 
    &amp;lt;InvstmtAcctDtls&amp;gt; 
     &amp;lt;AcctId&amp;gt; 
      &amp;lt;Prtry&amp;gt; &amp;lt;Id&amp;gt;##&amp;lt;/Id&amp;gt; &amp;lt;/Prtry&amp;gt; 
     &amp;lt;/AcctId&amp;gt; 
    &amp;lt;/InvstmtAcctDtls&amp;gt; 
    &amp;lt;IndvOrdrDtls&amp;gt; 
     &amp;lt;OrdrRef&amp;gt;##&amp;lt;/OrdrRef&amp;gt; 
      &amp;lt;FinInstrmDtls&amp;gt; 
       &amp;lt;Id&amp;gt; 
        &amp;lt;ISIN&amp;gt;##&amp;lt;/ISIN&amp;gt;     
       &amp;lt;/Id&amp;gt;  
      &amp;lt;/FinInstrmDtls&amp;gt; 
      &amp;lt;GrssAmt Ccy=&amp;quot;&amp;quot;&amp;gt;##&amp;lt;/GrssAmt&amp;gt;
      &amp;lt;PhysDlvryInd&amp;gt;##&amp;lt;/PhysDlvryInd&amp;gt; 
      &amp;lt;ReqdSttlmCcy&amp;gt;##&amp;lt;/ReqdSttlmCcy&amp;gt;
    &amp;lt;/IndvOrdrDtls&amp;gt; 
   &amp;lt;/MltplOrdrDtls&amp;gt; 
  &amp;lt;/SbcptOrdrV03&amp;gt; 
 &amp;lt;/Document&amp;gt; 
&amp;lt;/Payload&amp;gt; 
&amp;lt;/BaExchReq&amp;gt;&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Dynamic XML generation</title><link>https://community.appian.com/thread/76165?ContentTypeID=1</link><pubDate>Thu, 27 Aug 2020 08:27:55 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:afd5db80-c758-44c3-8fb4-2c46fec813ba</guid><dc:creator>Stewart Burchell</dc:creator><description>&lt;p&gt;What&amp;#39;s the Use Case? What XML format (XSD Schema) does the data need to be structured as? What is going to be consuming this data?&lt;/p&gt;
&lt;p&gt;Note: if you can retrieve the data and cast it to Appjan CDT format you can then use fn!toxml()&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>