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.

1

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

lxml.etree is full of win. Very convenient API, XPath support and as fast as you get.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.