mbm
mbm

Reputation: 1922

XML processing in Python

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.

Upvotes: 0

Views: 210

Answers (1)

Nicholas Riley
Nicholas Riley

Reputation: 44361

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.

Upvotes: 7

Related Questions