Work with Barcode Recognition State in XML
Overview
In addition to barcode recognition, the BarCodeReader class supports serializing the barcode recognition state and exporting it to XML format. The recognition state can be saved to a file using the ExportToXml(String) method or to a stream with the ExportToXml(Stream) method. Additionally, the recognition state can be imported from XML format using ImportFromXml(String) and ImportFromXml(Stream).
It is important to note that automatic serialization of barcode image information, source image file links, or the image itself is not supported. To include this data, use the SetBarCodeImage methods.
Save Barcode Recognition State to XML
Aspose.BarCode for JavaScript via C++ offers two methods to export the current state of the BarCodeReader class to XML: the ExportToXml(String) method for file export and ExportToXml(Stream) for stream export. The code snippet below demonstrates how to serialize the barcode recognition state to an XML file.
// Create a BarCodeReader instance and configure settings
var read = new BarCodeInstance.BarCodeReader();
read.BarcodeSettings.StripFNC = true;
read.QualitySettings.XDimension = BarCodeInstance.XDimensionMode.Small;
// Serialize the BarCodeReader
var xmlString = read.ExportToXml();
console.log(xmlString);
read.delete();
Load Barcode Recognition State from XML
The BarCodeReader class allows the current recognition state to be loaded from an XML file using the ImportFromXml(String) method or from a stream using the ImportFromXml(Stream) method. The barcode image must be specified using the SetBarCodeImage properties. The following code snippet shows how to load the state of a BarCodeReader object from an XML file.
// Load BarCodeReader
var read = BarCodeInstance.BarCodeReader.ImportFromXml(xmlString);
// Initialized data
console.log(`StripFNC: ${read.BarcodeSettings.StripFNC}`);
read.delete();