Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.
Originally posted by: SambaDancerDear all,
In the "XMLpy File" node, there is this nice trick where you can test if a field exists in the input XML.
- if so, output the field
- if not, create the field anyway and fill with NULL
An example of the trick would look something like this:
@elementHandler('/auditfile/transactions')
def transactionsHandler(element):
data = {}
data['fieldName'] = None
if hasattr(element, "fieldName"):
data['fieldName'] = element.fieldName
WOULD YOU KNOW IF THERE'S A SIMILAR TRICK ON NON-XML FIELDS???
The reason I ask is because I'm making a script based on source data that can vary slightly every time. For example: sometimes all address information is stored in 1 field "Address" and sometimes it is split accross multiple fields "Streetname", "HouseNumber", "PostalCode", etc. Upfront, I cannot predict which method is used, both are allowed.
Of course, I want the remainder of my script to be completely generic, so "somewhere" the fields need to exist, whether filled with NULLs or not...
Any ideas, anyone?
Greetings and thanks in advance from The Netherlands,
Bart...