def to_xml(self, opts = defaultdict(lambda: None)):
if not self.launch_url or not self.secure_launch_url:<EOL><INDENT>raise InvalidLTIConfigError('<STR_LIT>')<EOL><DEDENT>root = etree.Element('<STR_LIT>', attrib = {<EOL>'<STR_LIT>' %(NSMAP['<STR_LIT>'], '<STR_LIT>'): '<STR_LIT>',<EOL>'<STR_LIT>': '<STR_LIT>'<EOL>}, nsmap = NSMAP)<EOL>for key in ['<STR_LIT:title>', '<STR_LIT:description>', '<STR_LIT>', '<STR_LIT>']:<EOL><INDENT>option = etree.SubElement(root, '<STR_LIT>' %(NSMAP['<STR_LIT>'], key))<EOL>option.text = getattr(self, key)<EOL><DEDENT>vendor_keys = ['<STR_LIT:name>', '<STR_LIT:code>', '<STR_LIT:description>', '<STR_LIT:url>']<EOL>if any('<STR_LIT>' + key for key in vendor_keys) orself.vendor_contact_email:<EOL><INDENT>vendor_node = etree.SubElement(root, '<STR_LIT>'<EOL>%(NSMAP['<STR_LIT>'], '<STR_LIT>'))<EOL>for key in vendor_keys:<EOL><INDENT>if getattr(self, '<STR_LIT>' + key) != None:<EOL><INDENT>v_node = etree.SubElement(vendor_node,<EOL>'<STR_LIT>' %(NSMAP['<STR_LIT>'], key))<EOL>v_node.text = getattr(self, '<STR_LIT>' + key)<EOL><DEDENT><DEDENT>if getattr(self, '<STR_LIT>'):<EOL><INDENT>v_node = etree.SubElement(vendor_node,<EOL>'<STR_LIT>' %(NSMAP['<STR_LIT>'], '<STR_LIT>'))<EOL>c_name = etree.SubElement(v_node,<EOL>'<STR_LIT>' %(NSMAP['<STR_LIT>'], '<STR_LIT:name>'))<EOL>c_name.text = self.vendor_contact_name<EOL>c_email = etree.SubElement(v_node,<EOL>'<STR_LIT>' %(NSMAP['<STR_LIT>'], '<STR_LIT:email>'))<EOL>c_email.text = self.vendor_contact_email<EOL><DEDENT><DEDENT>if len(self.custom_params) != <NUM_LIT:0>:<EOL><INDENT>custom_node = etree.SubElement(root, '<STR_LIT>' %(NSMAP['<STR_LIT>'],<EOL>'<STR_LIT>'))<EOL>for (key, val) in sorted(self.custom_params.items()):<EOL><INDENT>c_node = etree.SubElement(custom_node, '<STR_LIT>'<EOL>%(NSMAP['<STR_LIT>'], '<STR_LIT>'))<EOL>c_node.set('<STR_LIT:name>', key)<EOL>c_node.text = val<EOL><DEDENT><DEDENT>if len(self.extensions) != <NUM_LIT:0>:<EOL><INDENT>for (key, params) in sorted(self.extensions.items()):<EOL><INDENT>extension_node = etree.SubElement(root, '<STR_LIT>' %(NSMAP['<STR_LIT>'],<EOL>'<STR_LIT>'), platform = key)<EOL>self.recursive_options(extension_node,params)<EOL><DEDENT><DEDENT>if getattr(self, '<STR_LIT>'):<EOL><INDENT>identifierref = etree.SubElement(root, '<STR_LIT>',<EOL>identifierref = self.cartridge_bundle)<EOL><DEDENT>if getattr(self, '<STR_LIT>'):<EOL><INDENT>identifierref = etree.SubElement(root, '<STR_LIT>',<EOL>identifierref = self.cartridge_icon)<EOL><DEDENT>return '<STR_LIT>' + etree.tostring(root)<EOL>
Generate XML from the current settings.