Ask Your Question
0

How do I create XML output?

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

metadaddy gravatar image

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

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

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

metadaddy gravatar image

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

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:
  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: image description

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

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

Seen: 38 times

Last updated: Jun 27 '17