Xml
|
The XmlPrinter type exposes the following members.
Name | Description | |
---|---|---|
Equals | (Inherited from Object) | |
GetHashCode | (Inherited from Object) | |
GetType | (Inherited from Object) | |
Print(Stream, String, String, Stream) | Print template formats using XML as input data. | |
Print(Stream, String, String, Stream, Boolean) | Print template formats using XML as input data with optional running commentary to standard out. | |
Print(String, Stream, String, String, Stream) | Print template formats using XML as input data to destinationDevice. | |
Print(String, Stream, String, String, Stream, Boolean) | Print template formats using XML as input data to a device with connection string destinationDevice. | |
ToString | (Inherited from Object) |
using System; using System.IO; using System.Text; using Zebra.Sdk.Printer; public class XmlPrinterExample { public static void Main(string[] args) { XmlPrintingExample(); CnXmlPrintingExample(); } /// These examples demonstrate how to use the one-line printing capability of the XmlPrinter class. /// /// They assume that a ZPL template containing variable fields appropriate to the XML data /// specified exists on the host device. In this case, a PC with the file named XmlPrinterExampleTemplate.zpl /// saved at "c:\XmlPrinterExampleTemplate.zpl". The contents of this file should be... /// /// ^XA^DFXmlExamp.zpl^FS /// ^A0N,100,100^FO100,100^FN1"Name"^FS /// ^A0N,100,100^FO100,200^FN2"Street"^FS /// ^A0N,100,100^FO100,300^FN3"City"^FS /// ^A0N,100,100^FO100,400^FN4"State"^FS /// ^A0N,100,100^FO100,500^FN5"Zip"^FS /// ^XZ private static void XmlPrintingExample() { // The possible inputs to the one-line XML printing function(s) string destinationDevice = "192.168.1.32"; string templateFilename = "c:\\XmlPrinterExampleTemplate.zpl"; string defaultQuantityString = "1"; bool verbose = true; // If the destination device argument is 'null' then any data that would have been // sent to a destination device, had one been specified, is captured in 'outputDataStream'. // This provides a way to test your output and configuration without having an actual // printer available or without wasting media even if a printer is available. Console.WriteLine("\nThe destinationDevice connection string argument is null:"); try { using (MemoryStream outputDataStream = new MemoryStream()) { using (Stream sourceStream = GetSampleXmlData()) { XmlPrinter.Print(null, sourceStream, templateFilename, defaultQuantityString, outputDataStream, verbose); Console.WriteLine(Encoding.UTF8.GetString(outputDataStream.ToArray())); } } } catch (Exception e) { Console.WriteLine(e.ToString()); } // The outputDataStream argument may be null, in which case the data generated by the XmlPrinter class will // not be logged but will be sent to the destination device. Console.WriteLine("\nThe outputDataStream argument is null:"); try { using (Stream sourceStream = GetSampleXmlData()) { XmlPrinter.Print(destinationDevice, sourceStream, templateFilename, defaultQuantityString, null, verbose); } } catch (Exception e) { Console.WriteLine(e.ToString()); } // Both destinationDevice connection string AND outputDataStream arguments may be specified, in which case the // data generated by the XmlPrinter class will be sent to the destination device and logged to the outputDataStream. Console.WriteLine("\nBoth destinationDevice connection string and outputDataStream arguments are specified:"); try { using (MemoryStream outputDataStream = new MemoryStream()) { using (Stream sourceStream = GetSampleXmlData()) { XmlPrinter.Print(destinationDevice, sourceStream, templateFilename, defaultQuantityString, outputDataStream, verbose); Console.WriteLine(Encoding.UTF8.GetString(outputDataStream.ToArray())); } } } catch (Exception e) { Console.WriteLine(e.ToString()); } // At least one of these two (destinationDevice connection string and outputDataStream) arguments should be specified. } private static Stream GetSampleXmlData() { string sampleXmlData = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<file _FORMAT=\"XmlExamp.zpl\">" + " <label>\n" + " <variable name=\"Name\">John Smith</variable>" + " <variable name=\"Street\">1234 Anystreet</variable>" + " <variable name=\"City\">Anycity</variable>" + " <variable name=\"State\">Anystate</variable>" + " <variable name=\"Zip\">12345</variable>" + " </label>\n" + " <label>\n" + " <variable name=\"Name\">Jane Doe</variable>" + " <variable name=\"Street\">5678 Anyroad</variable>" + " <variable name=\"City\">Anytown</variable>" + " <variable name=\"State\">Anystate</variable>" + " <variable name=\"Zip\">67890</variable>" + " </label>\n" + "</file>"; return new MemoryStream(Encoding.UTF8.GetBytes(sampleXmlData)); } /// This example demonstrates how to use the one-line printing capability of the XmlPrinter class. /// /// It assume that a ZPL template containing variable fields appropriate to the XML data /// specified exists on the host device. In this case, a PC with the file named CnXmlPrinterExampleTemplate.zpl /// saved at "c:\CnXmlPrinterExampleTemplate.zpl". The contents of this file should be... /// /// ^XA^DFCnXmlPrinterExampleTemplate.zpl^FS /// ^A@N,75,75,E:ANMDS.TTF^CI28^FO0,100^FN1"Customer Name"^FS /// ^A@N,75,75,E:ANMDS.TTF^FO0,200^FN2"Component Name"^FS^ /// ^A@N,75,75,E:ANMDS.TTF^FO0,300^FN3"Vendor Name"^FS /// ^A@N,75,75,E:ANMDS.TTF^FO0,400^FN4"Vendor ID"^FS /// ^A@N,75,75,E:ANMDS.TTF^FO0,500^FN5"Invoice Number"^FS /// ^XZ private static void CnXmlPrintingExample() { // The possible inputs to the one-line XML printing function(s) string destinationDevice = "192.168.1.32"; string templateFilename = "C:\\CnXmlPrinterExampleTemplate.zpl"; string defaultQuantityString = "1"; bool verbose = true; // The outputDataStream argument may be null, in which case the data generated by the XmlPrinter class will // not be logged but will be sent to the destination device. Console.WriteLine("\nThe outputDataStream argument is null:"); try { using (Stream sourceStream = GetSampleCnXmlData()) { XmlPrinter.Print(destinationDevice, sourceStream, templateFilename, defaultQuantityString, null, verbose); } } catch (Exception e) { Console.WriteLine(e.ToString()); } } private static Stream GetSampleCnXmlData() { string sampleXmlData = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<file _FORMAT=\"XmlExamp.zpl\">" + " <label>\n" + " <variable name=\"Customer Name\">东风伟世通汽车饰件系统有限公司</variable>" + " <variable name=\"Component Name\">驾驶员侧仪表板下装饰件</variable>" + " <variable name=\"Vendor Name\">供应商名称</variable>" + " <variable name=\"Vendor ID\">供应商代码</variable>" + " <variable name=\"Invoice Number\">订单号</variable>" + " </label>\n" + "</file>"; return new MemoryStream(Encoding.UTF8.GetBytes(sampleXmlData)); } }