def record_add_field(rec, tag, ind1='<STR_LIT>', ind2='<STR_LIT>', subfields=[],<EOL>controlfield_value='<STR_LIT>'):
if controlfield_value:<EOL><INDENT>doc = etree.Element("<STR_LIT>",<EOL>attrib={<EOL>"<STR_LIT>": tag,<EOL>})<EOL>doc.text = str(controlfield_value)<EOL><DEDENT>else:<EOL><INDENT>doc = etree.Element("<STR_LIT>",<EOL>attrib={<EOL>"<STR_LIT>": tag,<EOL>"<STR_LIT>": ind1,<EOL>"<STR_LIT>": ind2,<EOL>})<EOL>for code, value in subfields:<EOL><INDENT>field = etree.SubElement(doc, "<STR_LIT>", attrib={"<STR_LIT:code>": code})<EOL>field.text = value<EOL><DEDENT><DEDENT>rec.append(doc)<EOL>return rec<EOL>
Add a MARCXML datafield as a new child to a XML document.