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.
@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:
- includes two fields (
msg2) that are intended to be combined into one output XML element
vary 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 )
#if ($vary.getClass().getName() == "java.util.ArrayList")
#foreach( $v in $vary )
#elseif ($vary.getClass().getName() == "java.lang.String")
This will result in the following output:
Thank you @robin, your help is much appreciated.
@robin, would it be safe to assume that this will work for generating html files from XML generator snap?
Yes, though I would consider it “XHTML” (an old term)
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.