LoadXmlBeforeElementCallback Delegate

Summary
Optional delegate method that is used with the LoadXml methods.
Syntax
C#
C++/CLI
public delegate bool LoadXmlBeforeElementCallback( 
   LoadXmlBeforeElementData data 
) 
public delegate bool LoadXmlBeforeElementCallback(  
   LoadXmlBeforeElementData^ data 
) 

Parameters

data
An instance of the LoadXmlBeforeElementData class containing the progress callback data.

Return Value

true to include this DICOM element in the DicomDataSet; false to exclude the element from the DicomDataSet

Remarks

This delegate is called once for each DICOM element, before the element is added to the DicomDataSet. If you pass this delegate with the LoadXml methods, you must fill in certain fields of the data For details, see the documentation for LoadXmlBeforeElementData

Example
C#
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; 
 
using Leadtools.Codecs; 
 
public void SaveXmlCallbackExample() 
{ 
   string dicomFileNameIn = Path.Combine(LEAD_VARS.ImagesDir, "DICOM", "image3.dcm"); 
   string xmlFileNameOut = Path.Combine(LEAD_VARS.ImagesDir, "test.xml"); 
   string dicomFileNameOut = Path.Combine(LEAD_VARS.ImagesDir, "test.dcm"); 
 
   // Initialize DICOM engine 
   DicomEngine.Startup(); 
 
   DicomDataSet ds = new DicomDataSet(); 
 
   // Load an existing DICOM file 
   ds.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 file 
   DicomDataSetSaveXmlFlags xmlFlags = 
      DicomDataSetSaveXmlFlags.IgnoreBinaryData | 
      DicomDataSetSaveXmlFlags.TrimWhiteSpace | 
      DicomDataSetSaveXmlFlags.TagWithCommas; 
 
   ds.SaveXml(xmlFileNameOut, xmlFlags, new SaveXmlCallback(MySaveXmlCallback)); 
 
   // Use a LoadmlCallback to read the customized XML file 
   ds.LoadXml(xmlFileNameOut, DicomDataSetLoadXmlFlags.None, new LoadXmlBeforeElementCallback(MyLoadXmlBeforeElementCallback), new LoadXmlAfterElementCallback(MyLoadXmlAfterElementCallback)); 
 
   // Save the result -- there will be no pixel data 
   ds.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:\LEADTOOLS23\Resources\Images"; 
} 
Requirements

Target Platforms

Help Version 23.0.2024.2.29
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Dicom.Common Assembly
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.