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)