title: Error parsing a DTD using lxml
body: <p>I'm trying to write a validation script that will validate XML against the NITF DTD, <a href="http://www.iptc.org/std/NITF/3.4/specification/dtd/nitf-3-4.dtd" rel="nofollow noreferrer">http://www.iptc.org/std/NITF/3.4/specification/dtd/nitf-3-4.dtd</a>. Based on <a href="https://stackoverflow.com/questions/15798/how-do-i-validate-xml-against-a-dtd-file-in-python">this post</a> I came up with the following simple script to validate a NITF XML document. Bellow is the error message I get when the script is run, which isn't very descriptive and makes it hard to debug. Any help is appreciated.</p>
  
  <pre><code>#!/usr/bin/env python
  
  
  def main():
      from lxml import etree, objectify
      from StringIO import StringIO
  
      f = open('nitf_test.xml')
      xml_doc = f.read()
      f.close()
  
      f = open('nitf-3-4.dtd')
      dtd_doc = f.read()
      f.close()
  
      dtd = etree.DTD(StringIO(dtd_doc))
      tree = objectify.parse(StringIO(xml_doc))
      dtd.validate(tree)
  
  
  if __name__ == '__main__':
  
      main()
  </code></pre>
  
  <p>Traceback error message:</p>
  
  <pre><code>Traceback (most recent call last):
    File "./test_nitf_doc.py", line 23, in &lt;module&gt;
      main()
    File "./test_nitf_doc.py", line 16, in main
      dtd = etree.DTD(StringIO(dtd_doc))
    File "dtd.pxi", line 43, in lxml.etree.DTD.__init__ (src/lxml/lxml.etree.c:126056)
    File "dtd.pxi", line 117, in lxml.etree._parseDtdFromFilelike (src/lxml/lxml.etree.c:126727)
  lxml.etree.DTDParseError: error parsing DTD
  </code></pre>
  
  <p>If I change the line:</p>
  
  <pre><code>dtd = etree.DTD(StringIO(dtd_doc))
  </code></pre>
  
  <p>To:</p>
  
  <pre><code>dtd = etree.DTD(dtd_doc)
  </code></pre>
  
  <p>The error I get is:</p>
  
  <pre><code>lxml.etree.DTDParseError: failed to load external entity "NULL"
  </code></pre>