How do I create XML output?
I need to emit XML from my SDC pipeline. How do I do that?
You should be able to select XML as your output format in most destinations (including local FS, for example). It will essentially transform the full SDC record into XML. It might be possible to achieve the format you want by manipulating the SDC record field names/paths (using expression evaluator, etc.) in such a way that the generated XML looks the way you need as it is written to the destination. In that case, you will not need to do any scripting. If you want to do this in the middle of a pipeline (and capture the XML content in a STRING
field), you can use the Data Generator processor and select the XML format there.
You really should only need to do scripting if you need very specific control over the XML format that it outside of what can be generated easily.
You can use Jython ElementTree for this. For example, if your records have a name
field, and you want an XML person
element with a name
sub-element, you can use the Jython Evaluator with the following script:
from xml.etree import ElementTree as etree
for record in records:
try:
# Make element tree
person = etree.Element("person")
name = etree.SubElement(person, "body")
name.text = record.value['name']
# Put XML in the record
record.value['xml'] = etree.tostring(person)
output.write(record)
except Exception as e:
# Send record to error
error.write(record, str(e))
This results in output like:
Asked: 2017-06-14 10:30:36 -0600
Seen: 368 times
Last updated: Jun 27 '18