Ask Your Question

How do I create XML output?

asked 2017-06-14 10:30:36 -0500

metadaddy gravatar image

I need to emit XML from my SDC pipeline. How do I do that?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2017-06-14 10:35:06 -0500

metadaddy gravatar image

updated 2017-06-27 17:50:26 -0500

LC gravatar image

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:
    # 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)


  except Exception as e:
    # Send record to error
    error.write(record, str(e))

This results in output like: image description

edit flag offensive delete link more

answered 2018-04-10 13:51:13 -0500

jeff gravatar image

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.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower


Asked: 2017-06-14 10:30:36 -0500

Seen: 72 times

Last updated: Apr 10