0

So I'm trying to do roughly the following:

Take the following snippet of XML:

<?xml version="1.0" standalone="no"?>
<!DOCTYPE labels SYSTEM "label.dtd">
<labels _FORMAT="E:BARCODE2.ZPL" _QUANTITY="1" _DEVICENAME="ZBR3666875" _JOBNAME="BARC101">
  <label>
    <variable name="x">A-0000000</variable>
  </label>
</labels>

Parse it and extract the variable x, iterate over some range I give for x, which is a seven-digit barcode, and then have it send the XML to the device for each unique barcode.

I've looked into xml.etree and xml.dom.minidom, but I have very little experience processing XML in Python. I'm not looking for a detailed solution, just a helpful reference on what tool is best for the job. My thanks.

mbm
  • 1,902
  • 2
  • 19
  • 28

1 Answers1

7

Unless you're dealing with truly gigantic XML files, ElementTree is generally the easiest thing to use. There's the built-in implementations in Python and also lxml.etree which is mostly API-compatible but faster and more flexible.

Nicholas Riley
  • 43,532
  • 6
  • 101
  • 124
  • 3
    `lxml.etree` is full of win. Very convenient API, XPath support *and* as fast as you get. –  Dec 06 '10 at 20:08