title: Removing Processing Instructions with Python lxml
body: <p>I am using the python lxml library to transform XML files to a new schema but I've encountered problems parsing processing instructions from the XML body.</p>
  
  <p>The processing instruction elements are scattered throughout the XML, as in the following example (they all begin with "oasys" and end with a unique code):</p>
  
  <pre><code>string = "&lt;text&gt;&lt;?oasys _dc21-?&gt;Text &lt;i&gt;contents&lt;/i&gt;&lt;/text&gt;"
  </code></pre>
  
  <p>I can't locate them through the <code>lxml.etree.findall()</code> method, although <code>etree.getchildren()</code> returns them:</p>
  
  <pre><code>tree = lxml.etree.fromstring(string)
  print tree.findall(".//")
  &gt;&gt;&gt;&gt; [&lt;Element i at 0x747c&gt;]
  print tree.getchildren()
  &gt;&gt;&gt;&gt; [&lt;?oasys _dc21-?&gt;, &lt;Element i at 0x747x&gt;]
  print tree.getchildren()[0].tag
  &gt;&gt;&gt;&gt; &lt;built-in function ProcessingInstruction&gt;
  print tree.getchildren()[0].tail
  &gt;&gt;&gt;&gt; Text 
  </code></pre>
  
  <p>Is there an alternative to using <code>getchildren()</code> to parse and remove processing instructions, especially considering that they're nested at various levels throughout the XML? </p>