Skip to main content
Newcomer
March 25, 2024

Import XML to create objects

  • March 25, 2024
  • 2 replies
  • 0 views

Hi All, 

I have a process that exports a dashboard and all of its components to XML.  It then reads through the XML and creates new objects.  The process works when I import the XML by hand.  I was wondering if there is a way to have the code:

1) delete objects if they exist

2) import the XML to create the new objects. 

 

Thank you,
Scott

2 replies

Expert
March 25, 2024

The only method I know that will effectively replace Dashboards is XFProject. Have a look in the Design and Reference Guide and search this forum for more info. This screenshot gives you an idea:

MarcusH_0-1711380465932.png

 

Newcomer
March 25, 2024

I had looked at that.  Do you know if there a method to import and export the xfProj via code?  

 

Legend
March 25, 2024

XFProj has its own XML library: XFProjectWcf

Use XFProjectWcf.ExtractXFProjectFileHierarchy to extract,  and XFProjectWcf.StartLoadXFProjectFileHierarchy using similar structure to the code posted for application zip and dashboards.

Legend
March 25, 2024

You would use the XmlLoadWcf library for this.  It can load either xml as a string or as a zip file.  It runs similar to running a Data Management sequence, returning a TaskActivity object:

						
Dim task As TaskActivityItem = Nothing
'Execute the XML load and assign the TaskActivityItem
task = XmlLoadWcf.StartLoadXml(si, xmlString, Nothing,  String.Empty, SystemXmlFileType.Unknown, ApplicationXmlFileType.ApplicationDashboards, Nothing)


Here it is an example round trip using some of PeterFu's code:

Dim configSettings as AppServerConfigSettings = AppServerConfig.GetSettings(si)
Dim folderPath as String = FileShareFolderHelper.GetDataManagementExportUsernameFolderForApp(si, True, configSettings.FileShareRootFolder, si.AppToken.AppName) & "\" & DateTime.UtcNow.ToString("yyyyMMdd") & "\MetadataExtracts"
if Not Directory.Exists(folderPath) then Directory.CreateDirectory(folderPath)
Dim filePath as String = folderPath & "\" & si.AppToken.AppName & ".zip"				
If File.Exists(filePath) Then File.Delete(filePath)

'Set the extract options
Dim xmlOptions as New XmlExtractOptions
xmlOptions.ExtractAllItems = True

'Execute the Metadata Extract
Using dbConnFW as DBConnInfo = BRAPi.Database.CreateFrameworkDbConnInfo(si)
	Using dbConnApp as DBConnInfo = BRAPi.Database.CreateApplicationDbConnInfo(si)
		Dim zipBytes as Byte() = ApplicationZipFileHelper.Extract(dbConnFW, dbConnApp, Nothing, xmlOptions)
		'Append the contents of this workflow profile to the extract file			            
		Using FS As New FileStream(filePath, FileMode.Append, FileAccess.Write)			
			'Create a binary writer, and write all bytes to the FileStream at once
            Using BW As New BinaryWriter(FS)
                BW.Write(zipBytes)
            End Using
		End Using
	End Using
End Using

'Load the file back in
Dim task As TaskActivityItem = Nothing

'load the application zip file
task = XmlLoadWcf.StartLoadXml(si, "",  Nothing, filePath, SystemXmlFileType.Unknown, ApplicationXmlFileType.ApplicationZipFile, Nothing)

 

Newcomer
May 14, 2026

I tried this solution. The ZIP file loads and extracts normally, and the task manager shows it as loaded — but the loaded content isn't being retrieved/accessed as expected.