title: From Sax to Dom with DTD (python)
body: <p>I need a validated DomTree with DTD (to use <code>getElementById</code>).
  Validating and Parsing works, but the dom does't work properly:</p>
  
  <pre><code>from xml.dom import minidom 
  from xml.dom.pulldom import SAX2DOM
  from lxml import etree
  import lxml.sax
  from StringIO import StringIO
  
  data_string = """\
  &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;!DOCTYPE foo [
  &lt;!ELEMENT foo (bar)*&gt;
  &lt;!ELEMENT bar (#PCDATA)&gt;
  &lt;!ATTLIST bar id ID #REQUIRED&gt;]&gt;&lt;foo&gt;&lt;bar id="nr_0"&gt;text&lt;/bar&gt;&lt;/foo&gt; 
  """
  
  #parser, with vali. at parsing
  etree_parser = etree.XMLParser(dtd_validation=True,attribute_defaults=True) 
  #parse it
  sax_tree = etree.parse(StringIO(data_string),etree_parser);
  handler = SAX2DOM();
  lxml.sax.saxify(sax_tree,handler);
  domObject = handler.document;
  
  print domObject.getElementById("nr_0");
  #returns None
  
  print minidom.parseString(data_string).getElementById("nr_0");
  #returns &lt;DOM Element: bar at 0x7f36b77dc0e0&gt;
  </code></pre>
  
  <p>It seems that SAX2DOM wont pass the DTD to the dom. Did I forgott something?
  I've read it is impossible to load the DTD after the dom is build.</p>
  
  <p>any ideas?</p>