XMLPrinter not working in one case

I'm using the XMLPrinter.Print API call and 99% of the time it's working fine. I have one text description that has 3 sets of double quotes " in it, and when that label prints, the printer doesn't do anything and the returned stream is empty. No error thrown or anything.

call looks like this, and works for 99% of my labels

XmlPrinter.Print("10.0.0.129", sourceStream, "E:TESTTEMP.ZPL", "1", outputDataStream);

if I use this xml, it prints fine (2 sets of double quotes)

<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<file _FORMAT=\"E:TESTTEMP.ZPL\">
<label>
<variable name=\"Price\">$2.25</variable>
<variable name=\"Name\">100001</variable>
<variable name=\"Desc1\">1&quot; 2&quot;</variable>
<variable name=\"Barcode\">100001</variable>
</label>
</file>

But if I use the below XML
the printer doesn't print and the return stream is empty.

?xml version=\"1.0\" encoding=\"UTF-8\"?>
<file _FORMAT=\"E:TESTTEMP.ZPL\">
<label>
<variable name=\"Price\">$2.25</variable>
<variable name=\"Name\">100001</variable>
<variable name=\"Desc1\">1&quot; 2&quot; 3&quot;</variable>
<variable name=\"Barcode\">100001</variable>
</label>
</file>

Should I be escaping the double quotes differently?

Steven Si
Zebra ZPL printers have the

Zebra ZPL printers have the ability to store ZPL template, called Stored Format, in the printer’s flash or RAM memory. Then the application can just send the data in ZPL Recall Format to the printer to call out the Store Format. The printer will replace the variables in the Store Format with the values from the Recall Format, and then print the label. What XmlPrinter does is to send the Stored Format to the printer first, and then take the data from XML file and put the data into ZPL Recall Format to send to the printer to print.

If the data source is in XML, then you need to have a parser to extract the data from XML first, so that you can put the data into Recall Format. If the data source is other form, you need to have a different parser to extract the data.

Basically, we need two ZPL files, the Stored Format and the Recall Format. The key commands related to these formats are ^DF, ^XF and ^FN. Here is an example about how it works. There is also a tool called ZebraDesigner for Developer 3 (free) to help you to create the ZPL Stored and Recall Format template. With the Recall Format template, the application only needs to replace the variables in the Recall Format with the actual values before sending it to the printer.

You can also use FormatUtilLinkOs.printStoredFormatWithVarGraphics() API, instead of populating the Recall Format template.

Hope this helps.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Steven Si
You can use ZebraDesigner to

You can use ZebraDesigner to create either ZPL template or XML template. In either case, you can specify the quantity in their respective Recall Format. Since ZebraDesigner provides both Stored Format and Recall Form, there is no need to use PrintStoredFormatWithVarGraphics(). Just simply treat the template as files and use FileUtil.sendFileContents() or use Connection.write() to send the file content to the printer. Here is an example of XML template generated by ZebraDesigner. Since you already have the data source in XML, you would need a XML Stored Format. So you can send the XML Recall Format straight to the printer. You can test the XML template with Printer Setup Utility for Windows by sending them as separate files. The _QUANTITY="2" is used for specifying the number of copies to print. The ZPL template works the same way with slightly different syntax in the Stored Format and Recall Format. Hopefully you don't need to write your own parser or prepopulate the values. Just let the printer do the work for you.

In addition, the number of double quotes on the label is no longer an issue with the approach. You can either directly use " or use &quot; notation in the XML Recall Format.

XML Stored Format:

CT~~CD,~CC^~CT~
^XA
^DFR:XmlTest.ZPL^FS
~TA000
~JSN
^LT0
^MTT
^PON
^PMN
^LH0,0
^JMA
^PR8,8
~SD15
^JUS
^LRN
^CI27
^PA0,1,1,0
^MMT
^LS0
^FT42,47^A0N,20,20^FH\^CI28^FN1^FDfirstname^FS^CI27
^FT42,97^A0N,35,35^FH\^CI28^FN2^FDlastname^FS^CI27

^XZ

XML Recall Format:

<?xml version="1.0" standalone="no"?>
<labels _FORMAT="R:XmlTest.ZPL" _QUANTITY="2" _PRINTERNAME="ZDesigner for Developers - Generic Printer 200dpi" _JOBNAME="XmlTest">
    <label>
        <variable name="firstname">Zebra</variable>
        <variable name="lastname">Technologies</variable>
    </label>
</labels>

 

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Funky Gupta
useful informations

for more information visit - https://funkylife.in/alfaaz-shayari/

Vote: 
Vote up!
Vote down!

Points: -1

You voted ‘up’


Brian Baniewicz
same result

Yeah, I should have mentioned that's how I started, using \" . If I have an even number, it prints fine, if I have an odd number of \" it doesn't print and the resulting outputdatastream from XmlPrinter.Print is empty

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Steven Si
Thanks for providing the

Thanks for providing the additional detail. I also tried with odd numbers of \" in XML data and got the same result as you have seen, i.e. nothing prints. It seems a bug in the code that parses the XML data in XmlPrinter class. I don't think there is a way to get around this at the moment. If you want, you can write your own parser if you really need to have the odd numbers of the double quotes on the label.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Brian Baniewicz
parser

So most of our labels have dimensions on them, like 2" x 3" , and those are all OK. but some labels have 3 dimensional measurement, like 2" x 3" x 1" and those are the problem.

Any plans to update the SDK XmlPrinter class to fix?

if I went the write your own parser route, how would that integrate? instead of using XML print, I would have to generate my own ZPL?

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Steven Si
\" is a standard way to

\" is a standard way to escape double quotes. \"\"\" is to escape 3 double quotes in a row. Use \" instead for each double quote.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Brian Baniewicz
PrintStoredFormatWithVarGraphics

Actually, I started with PrintStoredFormatWithVarGraphics , and that works great, but doesn't have the ability to print a quantity (or at least I don't think is does). Where the XML print has a quantity variable. I had tried the zebradesigner for developers, using the "special" variables for print quantity, and couldn't get that to work. The Zebra support line said it didn't work and pointed me to the XML print, which solved that problem, but created a different one (the quotes).

So I think from what you said, I would recall the ZPL from the printer , which I already have stored as a template. and then do a string replace of the variables. I could probably also do a string replace on PQ at the end to print the quantity I needed?

Then I send the ZPL with replaced variables direct to the printer?

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Topic locked