โ04-18-2022 06:45 PM
Iโve 10+ columns which needs to go inside an XML generator snap; out of which, there is 1 column which has none to single to multiple values. For each of these records, how can I dynamically pass it to XML generator snap?
These values can be considered as web links that needs to be wrapped as a hyperlink and a title needs to be given (probably in XML generator as itโs dynamic); title is based on the weblink as the weblink has been formed with the concatenation of certain fields that will be used as a title.
For example, weblink is https://www.google.100snapLogic.com, title would be 100.snapLogic
Just for everyoneโs convenience, weblinks are different for each record and you guessed it right, title would be different too.
100 and snapLogic used in the weblink are values of different cols and we do have access to those column values.
Solved! Go to Solution.
โ04-21-2022 06:30 AM
Thanks @robin, I havenโt had a chance to test the solution you provided but Iโm sure it would have worked.
I went with a different route for my development so the concern I was having has been resolved.
XML Generator does intake dynamic values if they have been binded properly prior to it (using Aggregate or Group By), the only challenge I found was ingesting native html tags because <a href ="$URL">
wasnโt generating the desired output as the tags gets converted to snapLogicโs predefined symbols like < = <
,so on and so forth. Check these links for detailed explanation on tags conversion:
What I found and worked for me was defining the html format (if youโre trying to generate html files; could be any format youโre interested into) in the mapper itself/file writer and then let the format do its job.
Thanking @robin for his suggestions, time and help on this. Signing off from this thread.
โ04-19-2022 10:00 AM
@darshthakkar you can use the Apace Velocity support that is available within the Generator Snaps, for example
for the following input JSON (e.g. JSON Generator) that:
msg1
, msg2
) that are intended to be combined into one output XML elementvary
field that could be either null
, contain a single String value, or a list of string values[
{
"msg1" : "Hello", "msg2":"World", "num" : 1, "vary": null
},
{
"msg1" : "Hi", "msg2":"World", "num" : 2, "vary": "b"
},
{
"msg1" : "Hey", "msg2":"World", "num" : 3, "vary": ["b", "c"]
}
]
An XML Generator configuration like:
โUse default value for substitutionโ is enabled if you wish to replace any null
values with an empty String equivalent (see โDefault value for substitutionโ)
The โEdit XMLโ contains:
#set( $msg = $msg1 + " " + $msg2 )
<root>
<msg>$msg</msg>
<num>$num</num>
#if ($vary.getClass().getName() == "java.util.ArrayList")
#foreach( $v in $vary )
<vary>$v</vary>
#end
#elseif ($vary.getClass().getName() == "java.lang.String")
<vary>$vary</vary>
#end
</root>
This will result in the following output:
โ04-19-2022 10:06 AM
Thank you @robin, your help is much appreciated.
โ04-20-2022 05:08 AM
@robin, would it be safe to assume that this will work for generating html files from XML generator snap?
โ04-20-2022 03:31 PM
Yes, though I would consider it โXHTMLโ (an old term)