Optional delegate method that is used with the SaveXml methods.
public delegate bool SaveXmlCallback(SaveXmlData data)
Public Delegate Function SaveXmlCallback( _ByVal data As SaveXmlData _) As Boolean
public delegate bool SaveXmlCallback(SaveXmlData^ data)
data
An instance of the SaveXmlData interface containing the progress callback data.
true to write this DICOM element to the output XML file; false to skip writing this element to the output XML file.
This delegate is called once for each DICOM element before it is written to the XML file.
This example loads a sample DICOM file, and saves the contents as an XML file. The XML file output is customized by using the SaveXmlCallback delegate.
Then the customized XML file is read into a DicomDataSet object using the LoadXmlCallback
using Leadtools.Dicom;using Leadtools.Dicom.Common;using Leadtools.Dicom.Common.Extensions;using Leadtools;using Leadtools.Dicom.Common.Linq.BasicDirectory;using Leadtools.Dicom.Common.DataTypes;public void SaveXmlCallbackExample(){string dicomFileNameIn = Path.Combine(LEAD_VARS.ImagesDir, "IMAGE3.dcm");string xmlFileNameOut = Path.Combine(LEAD_VARS.ImagesDir, "test.xml");string dicomFileNameOut = Path.Combine(LEAD_VARS.ImagesDir, "test.dcm");// Initialize DICOM engineDicomEngine.Startup();DicomDataSet ds = new DicomDataSet();// Load an existing DICOM fileds.Load(dicomFileNameIn, DicomDataSetLoadFlags.None);// Save as XML to a file with no binary data// For the demo, keep the XML output file size small by skipping the pixel data// Use the SaveXmlCallback delegate to customize the XML fileDicomDataSetSaveXmlFlags xmlFlags =DicomDataSetSaveXmlFlags.IgnoreBinaryData |DicomDataSetSaveXmlFlags.TrimWhiteSpace |DicomDataSetSaveXmlFlags.TagWithCommas;ds.SaveXml(xmlFileNameOut, xmlFlags, new SaveXmlCallback(MySaveXmlCallback));// Use a LoadmlCallback to read the customized XML fileds.LoadXml(xmlFileNameOut, DicomDataSetLoadXmlFlags.None, new LoadXmlBeforeElementCallback(MyLoadXmlBeforeElementCallback), new LoadXmlAfterElementCallback(MyLoadXmlAfterElementCallback));// Save the result -- there will be no pixel datads.Save(dicomFileNameOut, DicomDataSetSaveFlags.None);DicomEngine.Shutdown();}private static bool MySaveXmlCallback(SaveXmlData data){//string sTag = data.attributes["tag"];//if (sTag.StartsWith("0008"))// return false;if (data.NodeType == DicomXmlNodeType.Comment){data.Comment = "COMMENT: customized xml file using the SaveXmlCallback";return false;}if (data.ElementName == "dataset"){data.Attributes.Add("new_attribute", "some_value");}else if (data.ElementName == "element"){data.ElementName = "element_newname";string sTagValue = data.Attributes["tag"];data.Attributes.Remove("tag");data.Attributes.Add("tag_newname", sTagValue);}return true;}private static bool MyLoadXmlBeforeElementCallback(LoadXmlBeforeElementData data){string sTagValue = data.Attributes["tag_newname"];long tag = 0;sTagValue = sTagValue.Replace(",", string.Empty);if (long.TryParse(sTagValue, System.Globalization.NumberStyles.HexNumber, null, out tag))data.Tag = tag;return true;}private static void MyLoadXmlAfterElementCallback(LoadXmlAfterElementData data){if (data.DicomElement.Tag == DicomTag.PixelData){// here you could call one of the following to set the pixel data// data.DicomDataSet.SetBinaryValue// data.DicomDataSet.SetImage()}}static class LEAD_VARS{public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";}
Imports Leadtools.DicomImports Leadtools.Dicom.CommonImports Leadtools.Dicom.Common.ExtensionsImports Leadtools.Dicom.Common.LinqImports Leadtools.Dicom.Common.Linq.BasicDirectoryImports LeadtoolsImports Leadtools.Dicom.Common.DataTypesPublic Sub SaveXmlCallbackExample()Dim dicomFileNameIn As String = Path.Combine(LEAD_VARS.ImagesDir, "IMAGE3.dcm")Dim xmlFileNameOut As String = Path.Combine(LEAD_VARS.ImagesDir, "test.xml")Dim dicomFileNameOut As String = Path.Combine(LEAD_VARS.ImagesDir, "test.dcm")' Initialize the DICOM engineDicomEngine.Startup()Dim ds As DicomDataSet = New DicomDataSet()' Load an existing DICOM fileds.Load(dicomFileNameIn, DicomDataSetLoadFlags.None)' Save as XML to a file with no binary data' For the demo, keep the XML output file size small by skipping the pixel data' Use the SaveXmlCallback delegate to customize the XML fileDim xmlFlags As DicomDataSetSaveXmlFlags = DicomDataSetSaveXmlFlags.IgnoreBinaryData Or DicomDataSetSaveXmlFlags.TrimWhiteSpace Or DicomDataSetSaveXmlFlags.TagWithCommasds.SaveXml(xmlFileNameOut, xmlFlags, New SaveXmlCallback(AddressOf MySaveXmlCallback))' Use a LoadmlCallback to read the customized XML fileds.LoadXml(xmlFileNameOut, DicomDataSetLoadXmlFlags.None, New LoadXmlBeforeElementCallback(AddressOf MyLoadXmlBeforeElementCallback), New LoadXmlAfterElementCallback(AddressOf MyLoadXmlAfterElementCallback))' Save the result -- there will be no pixel datads.Save(dicomFileNameOut, DicomDataSetSaveFlags.None)DicomEngine.Shutdown()End SubPrivate Function MySaveXmlCallback(ByVal data As SaveXmlData) As Boolean'string sTag = data.attributes["tag"];'if (sTag.StartsWith("0008"))' return false;If data.NodeType = DicomXmlNodeType.Comment Thendata.Comment = "COMMENT: customized xml file using the SaveXmlCallback"Return FalseEnd IfIf data.ElementName = "dataset" Thendata.Attributes.Add("new_attribute", "some_value")ElseIf data.ElementName = "element" Thendata.ElementName = "element_newname"Dim sTagValue As String = data.Attributes("tag")data.Attributes.Remove("tag")data.Attributes.Add("tag_newname", sTagValue)End IfReturn TrueEnd FunctionPrivate Function MyLoadXmlBeforeElementCallback(ByVal data As LoadXmlBeforeElementData) As BooleanDim sTagValue As String = data.Attributes("tag_newname")Dim tag As Long = 0sTagValue = sTagValue.Replace(",", String.Empty)If Long.TryParse(sTagValue, System.Globalization.NumberStyles.HexNumber, Nothing, tag) Thendata.Tag = tagEnd IfReturn TrueEnd FunctionPrivate Sub MyLoadXmlAfterElementCallback(ByVal data As LoadXmlAfterElementData)If data.DicomElement.Tag = DicomTag.PixelData Then' here you could call one of the following to set the pixel data' data.DicomDataSet.SetBinaryValue' data.DicomDataSet.SetImage()End IfEnd SubPublic NotInheritable Class LEAD_VARSPublic Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"End Class
SaveXmlCallback Members
Leadtools.Dicom.Common.Extensions Namespace
LoadXml(DicomDataSet,String,DicomDataSetLoadXmlFlags) Method
LoadXml(DicomDataSet,Stream,DicomDataSetLoadXmlFlags) Method
SaveXml(DicomDataSet,String,DicomDataSetSaveXmlFlags,SaveXmlCallback) Method
SaveXml(DicomDataSet,Stream,DicomDataSetSaveXmlFlags,SaveXmlCallback) Method
SaveXml(DicomDataSet,String,DicomDataSetSaveXmlFlags) Method
SaveXml(DicomDataSet,Stream,DicomDataSetSaveXmlFlags) Method
SaveXmlCallback Delegate
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document
