pro save_spedas_template,template=template,filename=filename,statuscode=statuscode,statusmsg=statusmsg
catch,Error_status
if (Error_status NE 0) then begin
statusmsg = !ERROR_STATE.MSG
statuscode = -3
catch,/cancel
return
endif
spd_ui_validate_file,filename=filename,statusmsg=statusmsg,statuscode=statuscode,/write
if statuscode lt 0 then return
xml_document=obj_new('IDLffXMLDOMDocument')
root_element=xml_document->CreateElement('body')
template->AppendXMLNewline,root_element
result = xml_document->AppendChild(root_element)
template->AppendXMLNewline,root_element
element = template->GetDOMElement(root_element)
template->AppendXMLNewline,root_element
result = root_element->AppendChild(element)
template->AppendXMLNewline,root_element
xml_document->Save,filename=filename
obj_destroy, xml_document
statuscode=0
statusmsg=STRING(filename,format='("SPEDAS template successfully saved to ",A)')
return
end