def makeup_fac(): d.documentElement.setAttributeNS(xsi.uri(), 'xsi:schemaLocation', foundation_schema) d.documentElement.setAttributeNS(xmlns.uri(), 'xmlns:xsi', xsi.uri()) return { 'cfdi': 'http://www.sat.gob.mx/cfd/3', 'xsi': 'http://www.w3.org/2001/XMLSchema-instance' }
def makeup_fac(): d.documentElement.setAttributeNS( xsi.uri(), 'xsi:schemaLocation', foundation_schema) d.documentElement.setAttributeNS(xmlns.uri(), 'xmlns:xsi', xsi.uri()) return { 'cfdi': 'http://www.sat.gob.mx/cfd/3', 'xsi': 'http://www.w3.org/2001/XMLSchema-instance' } def makeup_pag(): pag_schema = 'http://www.sat.gob.mx/Pagos http://www.sat.gob.mx/sitio_internet/cfd/Pagos/Pagos10.xsd' d.documentElement.setAttributeNS( xsi.uri(), 'xsi:schemaLocation', '{} {}'.format(foundation_schema, pag_schema)) d.documentElement.setAttributeNS(xmlns.uri(), 'xmlns:xsi', xsi.uri()) return { 'cfdi': 'http://www.sat.gob.mx/cfd/3', 'xsi': 'http://www.w3.org/2001/XMLSchema-instance' } try: namespace_set = { sa.CfdiType.FAC: makeup_fac, sa.CfdiType.NCR: makeup_fac, sa.CfdiType.PAG: makeup_pag, }[propos]() for prefix, uri in namespace_set.items(): ET.register_namespace(prefix, uri) except KeyError: raise Exception("To make up purpose {} is not supported yet".format(propos)) def indent(elem, level=0): """ in-place prettyprint formatter. Adds whitespaces to the tree because of ElementTree is not including such feature yet!. """ i = "\n" + level*" " if len(elem): if not elem.text or not elem.text.strip(): elem.text = i + " " if not elem.tail or not elem.tail.strip(): elem.tail = i for elem in elem: indent(elem, level+1) if not elem.tail or not elem.tail.strip(): elem.tail = i else: if level and (not elem.tail or not elem.tail.strip()): elem.tail = i root = ET.fromstring(d.toxml("utf-8").decode()) indent(root) t = ET.ElementTree(root) t.write(file_out, xml_declaration=True, encoding='utf-8', method="xml")
def makeup_pag(): pag_schema = 'http://www.sat.gob.mx/Pagos http://www.sat.gob.mx/sitio_internet/cfd/Pagos/Pagos10.xsd' d.documentElement.setAttributeNS( xsi.uri(), 'xsi:schemaLocation', '{} {}'.format(foundation_schema, pag_schema)) d.documentElement.setAttributeNS(xmlns.uri(), 'xmlns:xsi', xsi.uri()) return { 'cfdi': 'http://www.sat.gob.mx/cfd/3', 'xsi': 'http://www.w3.org/2001/XMLSchema-instance' }
def makeup_fac(): d.documentElement.setAttributeNS( xsi.uri(), 'xsi:schemaLocation', 'http://www.sat.gob.mx/cfd/3 http://www.sat.gob.mx/sitio_internet/cfd/3/cfdv33.xsd' ) d.documentElement.setAttributeNS(xmlns.uri(), 'xmlns:xsi', xsi.uri()) return { 'cfdi': 'http://www.sat.gob.mx/cfd/3', 'xsi': 'http://www.w3.org/2001/XMLSchema-instance' }
def writeGenePanelControlledVocabularies(geneVariantPanel): pyxb.utils.domutils.BindingDOMSupport.DeclareNamespace(cx.Namespace, 'cxx') docRoot = cx.CentraXXDataExchange() docRoot.Source = 'QBiC' qbicPrefix = 'QBIC-GENECV-' # fill in the controlled CV for gene variant profiles catData = cx.CatalogueDataType() # for each gene, we create an CustomCatalog/CV to specify the allowed variants for gene, variants in geneVariantPanel.iteritems(): # for each gene, add the general status of 'variation' or 'no variation' customCatalogObject = cx.CustomCatalogType() customCatalogObject.Code = qbicPrefix + gene tmpMultiLingua_en = cx.MultilingualEntryType(Lang='en', Value=gene) tmpMultiLingua_de = cx.MultilingualEntryType(Lang='de', Value=gene) customCatalogObject.NameMultilingualEntries = [ tmpMultiLingua_en, tmpMultiLingua_de ] customCatalogObject.CatalogUsage = 'GENERAL' customCatalogObject.Version = 1 customCatalogObject.EntityStatus = 'ACTIVE' customCatalogObject.CustomCatalogEntry = [] customCatalogEntryObject = createCustomCatalogEntry( 'VARIANTPRESENT', 'Variant(s) present', 'Variante(n) gefunden') customCatalogObject.CustomCatalogEntry.append(customCatalogEntryObject) customCatalogEntryObject = createCustomCatalogEntry( 'VARIANTABSENT', 'No variants present', 'Keine Varianten gefunden') customCatalogObject.CustomCatalogEntry.append(customCatalogEntryObject) for v in variants: if v == 'NOVARIANT': continue customCatalogEntryObject = createCustomCatalogEntry(v, v, v) customCatalogObject.CustomCatalogEntry.append( customCatalogEntryObject) catData.append(customCatalogObject) docRoot.CatalogueData = catData docRootDOM = docRoot.toDOM() docRootDOM.documentElement.setAttributeNS( xsi.uri(), 'xsi:schemaLocation', 'http://www.kairos-med.de ../CentraXXExchange.xsd') docRootDOM.documentElement.setAttributeNS(xmlns.uri(), 'xmlns:xsi', xsi.uri()) return (docRootDOM.toprettyxml(encoding='utf-8'))
def create_config(operator: RDOperator, context, filepath: str, meshpath: str, toplevel_directory: str, in_ros_package: bool, abs_filepaths=False): """ Creates the model.config file and exports it :param operator: The calling operator :param context: The current context # :param filepath: path to the SDF file # :param meshpath: Path to the mesh directory :param toplevel_directory: The directory in which to export :param in_ros_package: Whether to export into a ros package or plain files :param abs_filepaths: If not intstalled into a ros package decides whether to use absolute file paths. :return: """ # set namespace pyxb.utils.domutils.BindingDOMSupport.SetDefaultNamespace("http://schemas.humanbrainproject.eu/SP10/2017/model_config") # create model config element modelI = model_config_dom.model() # get model data modelI.name = bpy.context.active_object.name modelI.version = bpy.context.active_object.RobotEditor.modelMeta.model_version # get thumbnail data modelI.thumbnail = "thumbnail.png" # set sdf fixed name sdf = model_config_dom.sdf_versioned() sdf._setValue("model.sdf") sdf.version = 1.5 modelI.sdf = sdf # get author data author = model_config_dom.author_type(bpy.context.active_object.RobotEditor.author.authorName,bpy.context.active_object.RobotEditor.author.authorEmail) modelI.author = author modelI.description = bpy.context.active_object.RobotEditor.modelMeta.model_description # export model.config file with open(toplevel_directory + "/model.config", "w") as f: output = modelI.toDOM() output.documentElement.setAttributeNS(xsi.uri(), 'xsi:schemaLocation','http://schemas.humanbrainproject.eu/SP10/2017/model_config ../model_configuration.xsd') output.documentElement.setAttributeNS(xsi.uri(), 'xmlns:xsi','http://www.w3.org/2001/XMLSchema-instance') output = output.toprettyxml() f.write(output)
def writeMeasurementParameterDefs(geneVariantPanel): pyxb.utils.domutils.BindingDOMSupport.DeclareNamespace(cx.Namespace, 'cxx') docRoot = cx.CentraXXDataExchange() docRoot.Source = 'QBiC' qbicPrefix = 'QBIC-GENEPARAM-' # fill in the controlled CV for gene variant profiles catData = cx.CatalogueDataType() flexValues = cx.FlexibleValuesType() flexValues.FlexibleCatalogValue = [] # for each gene variant create a UsageEntryCatalogueItem for gene, variants in geneVariantPanel.iteritems(): flexCatalogValue = cx.FlexibleCatalogType() flexCatalogValue.Code = qbicPrefix + gene tmpMultiLingua_en = cx.MultilingualEntryType(Lang='en', Value=gene + ' variants') tmpMultiLingua_de = cx.MultilingualEntryType(Lang='de', Value=gene + '-Varianten') flexCatalogValue.NameMultilingualEntries = [ tmpMultiLingua_en, tmpMultiLingua_de ] flexCatalogValue.ChoiseType = 'SELECTMANY' flexCatalogValue.UserDefinedCatalogRef = cx.UserDefinedCatalogRefType( Code='QBIC-GENECV-' + gene, Version='1') flexValues.append(flexCatalogValue) #catData.append(tmpCatDataItem) catData.append(flexValues) docRoot.CatalogueData = catData try: docRootDOM = docRoot.toDOM() except pyxb.ValidationError as e: print(e.details()) docRootDOM.documentElement.setAttributeNS( xsi.uri(), 'xsi:schemaLocation', 'http://www.kairos-med.de ../CentraXXExchange.xsd') docRootDOM.documentElement.setAttributeNS(xmlns.uri(), 'xmlns:xsi', xsi.uri()) return (docRootDOM.toprettyxml(encoding='utf-8'))
def add_document_files(self, zipfile): dom = self.metadata.toDOM(element_name='paket') dom.documentElement.setAttributeNS( xsi.uri(), u'xsi:schemaLocation', u'http://bar.admin.ch/arelda/v4 xsd/arelda.xsd', ) dom.documentElement.setAttributeNS( xsi.uri(), u'xsi:type', u'paketSIP', ) arcname = os.path.join(self.get_folder_name(), 'header', 'metadata.xml') zipfile.writestr(arcname, dom.toprettyxml(encoding='UTF-8'))
def add_document_files(self, zipfile): dom = self.metadata.toDOM(element_name='paket') dom.documentElement.setAttributeNS( xsi.uri(), u'xsi:schemaLocation', u'http://bar.admin.ch/arelda/v4 xsd/arelda.xsd', ) dom.documentElement.setAttributeNS( xsi.uri(), u'xsi:type', u'paketSIP', ) arcname = os.path.join( self.get_folder_name(), 'header', 'metadata.xml') zipfile.writestr(arcname, dom.toprettyxml(encoding='UTF-8'))
def to_dom(self): """ Convert into DOM and map the various namespaces :return: """ domutils.BindingDOMSupport.SetDefaultNamespace(Namespace) exclusions = [ ns for ns in exclude_namespaces if ns not in self.namespaces ] if exclusions: self._schema.exclude_prefixes = ' '.join(exclusions) schema_dom = self._schema.toDOM() bs = domutils.BindingDOMSupport() for ns, url in self.namespaces.items(): if ns: bs.addXMLNSDeclaration( schema_dom.documentElement, pyxb.namespace.NamespaceForURI(url, create_if_missing=True), ns) schema_dom.documentElement.setAttributeNS( Namespace.uri(), 'xsi:schemaLocation', 'http://www.w3.org/shex/ ../xsd/ShEx.xsd') schema_dom.documentElement.setAttributeNS(Xmlns.uri, 'xmlns:xsi', Xsi.uri()) return schema_dom
def to_dom(self): """ Convert into DOM and map the various namespaces :return: """ domutils.BindingDOMSupport.SetDefaultNamespace(Namespace) exclusions = [ns for ns in exclude_namespaces if ns not in self.namespaces] if exclusions: self._schema.exclude_prefixes = ' '.join(exclusions) schema_dom = self._schema.toDOM() bs = domutils.BindingDOMSupport() for ns, url in self.namespaces.items(): if ns: bs.addXMLNSDeclaration(schema_dom.documentElement, pyxb.namespace.NamespaceForURI(url, create_if_missing=True), ns) schema_dom.documentElement.setAttributeNS(Namespace.uri(), 'xsi:schemaLocation', 'http://www.w3.org/shex/ ../xsd/ShEx.xsd') schema_dom.documentElement.setAttributeNS(Xmlns.uri, 'xmlns:xsi', Xsi.uri()) return schema_dom
def createPatientExport(vcfPanel, qPatientID, qSampleID, patientMPI, pgmSampleID, creationTimeStamp='1970-01-01T11:59:59', panelName='Unknown gene panel'): pyxb.utils.domutils.BindingDOMSupport.DeclareNamespace(cx.Namespace, 'cxx') docRoot = cx.CentraXXDataExchange() docRoot.Source = 'XMLIMPORT' effData = cx.EffectDataType() # fill in the controlled CV for gene variant profiles #catData = cx.CatalogueDataType() # for each gene variant create a UsageEntryCatalogueItem #docRoot.CatalogueData = catData patientData = cx.PatientDataSetType() patientData.Source = 'XMLIMPORT' patientIDcontainer = cx.IDContainerType() patientFlexID = cx.FlexibleIDType('MPI', patientMPI) patientIDcontainer.append(patientFlexID) patientFlexID = cx.FlexibleIDType('QBIC_PAT_ID', qPatientID) patientIDcontainer.append(patientFlexID) patientData.IDContainer = patientIDcontainer masterData = cx.PatientMasterdataType() patientData.Masterdata = masterData # container for samples (MasterSample) sampleData = cx.SampleDataType() newMasterSample = cx.MasterSampleType() newMasterSample.Source = 'XMLIMPORT' sampleIDcontainer = cx.SampleIDContainerType() sampleFlexID = cx.FlexibleIDType('SAMPLEID', pgmSampleID) sampleIDcontainer.append(sampleFlexID) sampleFlexID = cx.FlexibleIDType('QBIC_SAMPLE_ID', qSampleID) sampleIDcontainer.append(sampleFlexID) newMasterSample.SampleIDContainer = sampleIDcontainer newMasterSample.SampleTypeCatalogueTypeRef = 'UNKN' newMasterSample.OrganisationUnitTypeRef = 'QBIC' newMasterSample.SampleReceptacleTypeRef = 'KRYO' newMasterSample.HasChildren = False newMasterSample.AmountRest = cx.VolumeType(1.0, cx.AmountUnitEnumType.PC) newMasterSample.InitialAmount = cx.VolumeType(1.0, cx.AmountUnitEnumType.PC) newMasterSample.SampleKind = cx.SampleKindEnumType.TISSUE newMasterSample.SampleLocationRef = 'QBIC_STORAGE' newMasterSample.UseSPREC = False newMasterSample.VirtualPatient = False newMasterSample.XPosition = 0 newMasterSample.YPosition = 0 # todo was fixed... we have now the timestamp of the PGM vcf in here samplingDate = cx.DateType() # pytz.timezone('Europe/Berlin') #currDateTime = datetime.datetime.now() #print(creationTimeStamp) dateTimeObject = parser.parse(creationTimeStamp) #timeFormat = '%Y-%m-%dT%H:%M:%S%z' samplingDate.Date = dateTimeObject.isoformat() samplingDate.Precision = cx.DatePrecision.EXACT newMasterSample.SamplingDate = samplingDate newMasterSample.RepositionDate = samplingDate newMasterSample.FirstRepositionDate = samplingDate newMasterSample.SopDeviation = False # here we generate a unique id for cross-linking flexible datasets sampleCrossLink = qSampleID + '-' + str(uuid.uuid4()) newMasterSample.FlexibleDataSetRef = [sampleCrossLink] # Sample aus welchem Tissue/Organ? #newMasterSample.OrganSampleRef = 'Organ' patientData.OrganisationUnitRefs.append('QBIC') try: sampleData.append(newMasterSample) except pyxb.ValidationError as e: print(e.details()) try: patientData.SampleData = sampleData except pyxb.ValidationError as e: print(e.details()) try: effData.append(patientData) except pyxb.ValidationError as e: print(e.details()) # Here, we write the actual variant data variantDataSet = cx.FlexibleDataSetInstanceType() #variantDataSet.Source = 'QBIC' variantDataSet.FlexibleDataSetTypeRef = 'QBIC-GENEPANEL-V1' variantDataSet.InstanceName = panelName variantDataSet.Date = samplingDate #variantDataSet.Date.Date = dateTimeObject.isoformat() #variantDataSet.Date.Precision = cx.DatePrecision.EXACT variantDataSet.Code = 'QBIC-GENEPANEL-V1-INSTANCE-' + qSampleID variantDataSet.FlexibleDataSetInstanceRef = sampleCrossLink # loop over gene variants in vcfPanel and write the corresponding XML elements enumValues = [] for gene, muts in vcfPanel.iteritems(): flexValue = cx.FlexibleEnumerationDataType() flexValue.FlexibleValueTypeRef = 'QBIC-GENEPARAM-' + gene # TODO: need to check here if referenced by code or value flexValue.UserDefinedCatalogEntryRef = [] for mut in muts: flexValue.UserDefinedCatalogEntryRef.append(mut) enumValues.append(flexValue) variantDataSet.EnumerationValue = enumValues # try: # variantDataSet.append(flexValues) # except pyxb.ValidationError as e: # print("APPEND\n" + e.details()) try: effData.append(variantDataSet) except pyxb.ValidationError as e: print(e.details()) try: docRoot.EffectData = effData except pyxb.IncompleteElementContentError as e: print(e.details()) # initialize docRootDOM with an empty document domimpl = getDOMImplementation() docRootDOM = domimpl.createDocument(None, "init", None) try: docRootDOM = docRoot.toDOM() except pyxb.IncompleteElementContentError as e: print(e.details()) docRootDOM.documentElement.setAttributeNS( xsi.uri(), 'xsi:schemaLocation', 'http://www.kairos-med.de ../CentraXXExchange.xsd') docRootDOM.documentElement.setAttributeNS(xmlns.uri(), 'xmlns:xsi', xsi.uri()) return (docRootDOM.toprettyxml(encoding='utf-8'))
measAll = QIFDocument.MeasureEvaluateAll() steps = QIFDocument.UnnumberedPlanElementsType() steps.n = 1 steps.PlanElement.append(measAll) #planRoot = QIFDocument.UnorderedActionGroupType() this approach leads to xsi:type substitution group behavior group which QIF doesn't support planRoot = QIFDocument.UnorderedPlanRoot() planRoot.Steps = steps measPlan = QIFDocument.MeasurementPlanType() measPlan.PlanRoot = planRoot qifdata.MeasurementPlan = measPlan #endregion # make the DOM instance and add the schema location manually dominstance = qifdata.toDOM() from pyxb.namespace import XMLSchema_instance as xsi dominstance.documentElement.setAttributeNS(xsi.uri(), 'xmlns:xsd', 'http://www.w3.org/2001/XMLSchema') dominstance.documentElement.setAttributeNS( xsi.uri(), 'xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance') dominstance.documentElement.setAttributeNS( xsi.uri(), 'xsi:schemaLocation', 'http://qifstandards.org/xsd/qif2 ../QIFApplications/QIFDocument.xsd') # make a pretty QIF document xmls = dominstance.toprettyxml(indent=" ", encoding="utf-8", newl='\r\n') root = tkinter.Tk() root.withdraw() file_path = tkinter.filedialog.asksaveasfilename( title="Save QIF file:", filetypes=(("QIF files", "*.qif"), ("all files", "*.*")))
def writeMeasurementProfileDef(geneVariantPanel): pyxb.utils.domutils.BindingDOMSupport.DeclareNamespace(cx.Namespace, 'cxx') docRoot = cx.CentraXXDataExchange() docRoot.Source = 'QBiC' qbicPrefix = 'QBIC-GENEPARAM-' # fill in the controlled CV for gene variant profiles catData = cx.CatalogueDataType() geneProfile = cx.FlexibleDataSetType() geneProfile.Code = 'QBIC-GENEPANEL-V1' tmpMultiLingua_en = cx.MultilingualEntryType( Lang='en', Value='QBiC Gene Variant Panel v1') tmpMultiLingua_de = cx.MultilingualEntryType( Lang='de', Value='QBiC Gene Variant Panel v1') geneProfile.NameMultilingualEntries = [ tmpMultiLingua_en, tmpMultiLingua_de ] geneProfile.FlexibleValueComplexRefs = [] #FlexibleValueComplexRefs for gene, variants in geneVariantPanel.iteritems(): flexValRef = cx.FlexibleValueRefType(qbicPrefix + gene, False) geneProfile.FlexibleValueComplexRefs.append(flexValRef) #catData.append(tmpCatDataItem) geneProfile.FlexibleDataSetType = 'MEASUREMENT' geneProfile.Systemwide = True geneProfile.Category = 'LABOR' crfTemplateObject = cx.CrfTemplateType() crfTemplateObject.Name = 'QBiC Genpanel v1' crfTemplateSection = cx.CrfTemplateSectionType() crfTemplateSection.Name = 'Gene und zugehoerige Varianten' crfTemplateSection.CrfTemplateField = [] rowNumber = 0 for gene, variants in geneVariantPanel.iteritems(): crfTemplateField = cx.CrfTemplateFieldType() crfTemplateField.LaborValue = qbicPrefix + gene crfTemplateField.LowerRow = str(rowNumber) crfTemplateField.UpperRow = str(rowNumber) crfTemplateField.LowerColumn = '0' crfTemplateField.UpperColumn = '0' crfTemplateField.Mandatory = False crfTemplateField.VisibleCaption = True crfTemplateField.FieldType = 'LABORVALUE' crfTemplateField.CustomCatalogEntryDefaultValueRef = [ 'VARIANTPRESENT', 'VARIANTABSENT' ] for v in variants: if v == 'NOVARIANT': continue crfTemplateField.CustomCatalogEntryDefaultValueRef.append(v) crfTemplateSection.CrfTemplateField.append(crfTemplateField) rowNumber += 1 crfTemplateObject.CrfTemplateSection = [crfTemplateSection] crfTemplateObject.FlexibleDataSetRef = 'QBIC-GENEPANEL-V1' crfTemplateObject.TemplateType = 'LABORMETHOD' crfTemplateObject.Version = '0' crfTemplateObject.EntityStatus = 'ACTIVE' crfTemplateObject.Global = False crfTemplateObject.MultipleUse = False crfTemplateObject.Active = False try: catData.append(geneProfile) except pyxb.ValidationError as e: print(e.details()) catData.append(crfTemplateObject) docRoot.CatalogueData = catData try: docRootDOM = docRoot.toDOM() except pyxb.ValidationError as e: print(e.details()) docRootDOM.documentElement.setAttributeNS( xsi.uri(), 'xsi:schemaLocation', 'http://www.kairos-med.de ../CentraXXExchange.xsd') docRootDOM.documentElement.setAttributeNS(xmlns.uri(), 'xmlns:xsi', xsi.uri()) return (docRootDOM.toprettyxml(encoding='utf-8'))
def create_config(operator: RDOperator, context, filepath: str, meshpath: str, toplevel_directory: str, in_ros_package: bool, abs_filepaths=False): """ Creates the model.config file and exports it :param operator: The calling operator :param context: The current context # :param filepath: path to the SDF file # :param meshpath: Path to the mesh directory :param toplevel_directory: The directory in which to export :param in_ros_package: Whether to export into a ros package or plain files :param abs_filepaths: If not intstalled into a ros package decides whether to use absolute file paths. :return: """ # set namespace pyxb.utils.domutils.BindingDOMSupport.SetDefaultNamespace( "http://schemas.humanbrainproject.eu/SP10/2017/model_config") # create model config element modelI = model_config_dom.model() # get model data modelI.name = bpy.context.active_object.name modelI.version = bpy.context.active_object.RobotEditor.modelMeta.model_version # get thumbnail data modelI.thumbnail = "thumbnail.png" # set sdf fixed name sdf = model_config_dom.sdf_versioned() sdf._setValue("model.sdf") sdf.version = 1.5 modelI.sdf = sdf # get author data author = model_config_dom.author_type( bpy.context.active_object.RobotEditor.author.authorName, bpy.context.active_object.RobotEditor.author.authorEmail) modelI.author = author modelI.description = bpy.context.active_object.RobotEditor.modelMeta.model_description # export model.config file with open(toplevel_directory + "/model.config", "w") as f: output = modelI.toDOM() output.documentElement.setAttributeNS( xsi.uri(), 'xsi:schemaLocation', 'http://schemas.humanbrainproject.eu/SP10/2017/model_config ../model_configuration.xsd' ) output.documentElement.setAttributeNS( xsi.uri(), 'xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance') output = output.toprettyxml() f.write(output)
measAll = QIFDocument.MeasureEvaluateAll() steps = QIFDocument.UnnumberedPlanElementsType() steps.n = 1 steps.PlanElement.append(measAll) #planRoot = QIFDocument.UnorderedActionGroupType() this approach leads to xsi:type substitution group behavior group which QIF doesn't support planRoot = QIFDocument.UnorderedPlanRoot() planRoot.Steps = steps measPlan = QIFDocument.PlanType() measPlan.PlanRoot = planRoot qifdata.MeasurementPlan = measPlan #endregion # make the DOM instance and add the schema location manually dominstance = qifdata.toDOM() from pyxb.namespace import XMLSchema_instance as xsi dominstance.documentElement.setAttributeNS(xsi.uri(), 'xmlns:xsd', 'http://www.w3.org/2001/XMLSchema') dominstance.documentElement.setAttributeNS(xsi.uri(), 'xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance') dominstance.documentElement.setAttributeNS(xsi.uri(), 'xsi:schemaLocation', 'http://qifstandards.org/xsd/qif3 ../QIFApplications/QIFDocument.xsd') # make a pretty QIF document xmls = dominstance.toprettyxml(indent = " ", encoding = "utf-8", newl='\r\n') root = tkinter.Tk() root.withdraw() file_path = tkinter.filedialog.asksaveasfilename(title = "Save QIF file:", filetypes = (("QIF files","*.qif"),("all files","*.*"))) # write it open(file_path, 'wb').write(xmls) # xmls is a list of bytes # lets take a look os.system('Notepad.exe '+ file_path )