Intermec PC43d IDL Smart Printing Resource Kit Developer Guide - Page 20

How to Use XML Serialization for Stored Label Formats

Page 20 highlights

How to Use XML Serialization for Stored Label Formats Because the Smart Printing API provides access to directly read or modify the list of objects attached to a label, you can serialize your label formats. The Smart Printing Resource Kit provides a sample application illustrating how to serialize label formats. The sample is located at: c:\Intermec\SmartPrintingRK\Examples\Code\XmlSerialization.cs Populate an Imported Label Format with Variable Data There is no built-in method to set variable data fields in the Drawing objects, as XmlSerialization is a generic feature. Intermec recommends that you use an iterator to go through all the objects in the Drawing.DrawingObjects list and search and replace data in the Data property. If the XML format is being generated by a C# application, you may choose to set the property Name for each object, which allows you to identify an object in the DrawingObjects list by a textual identifier of your choice. Sample Code: Export Label Objects in a Drawing private static void ExportXml(Drawing drawing, string filename) { // Serialize the label format (objects) to XML XmlSerializer xmlSerializer = new XmlSerializer(typeof(List)); TextWriter textWriter = new StreamWriter(filename); xmlSerializer.Serialize(textWriter, drawing.DrawingObjects); textWriter.Close(); } Sample Code: Import Label Objects to a Drawing private static void ImportXml(Drawing drawing, string filename) { // Deserialize/import label format from XML XmlSerializer xmlDeserializer = new XmlSerializer(typeof(List)); TextReader textReader = new StreamReader(filename); drawing.DrawingObjects = (List)xmlDeserializer.Deserialize(textReader); textReader.Close(); } 14 IDL Smart Printing Resource Kit Developer Guide

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28

14
IDL Smart Printing Resource Kit Developer Guide
How to Use XML Serialization for Stored Label Formats
Because the Smart Printing API provides access to directly read or modify the list of
objects attached to a label, you can serialize your label formats.
The Smart Printing Resource Kit provides a sample application illustrating how to
serialize label formats. The sample is located at:
c:\Intermec\SmartPrintingRK\Examples\Code\XmlSerialization.cs
Populate an Imported Label Format with Variable Data
There is no built-in method to set variable data fields in the Drawing objects, as
XmlSerialization is a generic feature. Intermec recommends that you use an iterator
to go through all the objects in the Drawing.DrawingObjects list and search and
replace data in the Data property.
If the XML format is being generated by a C# application, you may choose to set the
property Name for each object, which allows you to identify an object in the
DrawingObjects list by a textual identifier of your choice.
Sample Code: Export Label Objects in a Drawing
private static void ExportXml(Drawing drawing, string filename)
{
// Serialize the label format (objects) to XML
XmlSerializer xmlSerializer =
new XmlSerializer(typeof(List<Drawing.Base>));
TextWriter textWriter = new StreamWriter(filename);
xmlSerializer.Serialize(textWriter, drawing.DrawingObjects);
textWriter.Close();
}
Sample Code: Import Label Objects to a Drawing
private static void ImportXml(Drawing drawing, string filename)
{
// Deserialize/import label format from XML
XmlSerializer xmlDeserializer =
new XmlSerializer(typeof(List<Drawing.Base>));
TextReader textReader = new StreamReader(filename);
drawing.DrawingObjects =
(List<Drawing.Base>)xmlDeserializer.Deserialize(textReader);
textReader.Close();
}