title: Separate big xml into multiple small xml file
body: <p>This is the books.xml which contains all the information of books.</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;root&gt;
  &lt;Book&gt;
      &lt;Name&gt;
          Book1
      &lt;/Name&gt;
      &lt;Price&gt;
          USD.10.00
      &lt;/Price&gt;
  &lt;/Book&gt;
  
  &lt;Book&gt;
      &lt;Name&gt;
          Book2
      &lt;/Name&gt;
      &lt;Price&gt;
          USD.15.40
      &lt;/Price&gt;
  &lt;/Book&gt;
  
  &lt;Book&gt;
      &lt;Name&gt;
          Book3
      &lt;/Name&gt;
      &lt;Price&gt;
          USD.435.90
      &lt;/Price&gt;
  &lt;/Book&gt;
  
  &lt;Book&gt;
      &lt;Name&gt;
          Book1
      &lt;/Name&gt;
      &lt;Price&gt;
          EUR.15.40
      &lt;/Price&gt;
  &lt;/Book&gt;
  
  &lt;Book&gt;
      &lt;Name&gt;
          Book2
      &lt;/Name&gt;
      &lt;Price&gt;
          EUR.66.40
      &lt;/Price&gt;
  &lt;/Book&gt;
  
  &lt;Book&gt;
      &lt;Name&gt;
          Book1
      &lt;/Name&gt;
      &lt;Price&gt;
          GBP.10.20
      &lt;/Price&gt;
  &lt;/Book&gt;
  &lt;/root&gt;
  </code></pre>
  <p>With the given books.xml, i want it to generate multiple xml files according to the currency</p>
  <p>Output I desire</p>
  <p>USD_books.xml</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
     &lt;Book&gt;
      &lt;Name&gt;
          Book1
      &lt;/Name&gt;
      &lt;Price&gt;
          USD.10.00
      &lt;/Price&gt;
  &lt;/Book&gt;
  
  &lt;Book&gt;
      &lt;Name&gt;
          Book2
      &lt;/Name&gt;
      &lt;Price&gt;
          USD.15.40
      &lt;/Price&gt;
  &lt;/Book&gt;
  
  &lt;Book&gt;
      &lt;Name&gt;
          Book3
      &lt;/Name&gt;
      &lt;Price&gt;
          USD.435.90
      &lt;/Price&gt;
  &lt;/Book&gt;
  </code></pre>
  <p>EUR_books.xml</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;Book&gt;
      &lt;Name&gt;
          Book1
      &lt;/Name&gt;
      &lt;Price&gt;
          EUR.15.40
      &lt;/Price&gt;
  &lt;/Book&gt;
  
  &lt;Book&gt;
      &lt;Name&gt;
          Book2
      &lt;/Name&gt;
      &lt;Price&gt;
          EUR.66.40
      &lt;/Price&gt;
  &lt;/Book&gt;   
  </code></pre>
  <p>GDP_books.xml</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;Book&gt;
      &lt;Name&gt;
          Book1
      &lt;/Name&gt;
      &lt;Price&gt;
          GBP.10.20
      &lt;/Price&gt;
  &lt;/Book&gt;
  </code></pre>
  <p>The output I am getting is:</p>
  <p>GPB_books.xml</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;Book&gt;
      &lt;Name&gt;
          Book1
      &lt;/Name&gt;
      &lt;Price&gt;
          GBP.10.20
      &lt;/Price&gt;
  &lt;/Book&gt;
  </code></pre>
  <p>EUR_books.xml</p>
  <pre><code>&lt;Book&gt;
          &lt;Name&gt;
              Book2
          &lt;/Name&gt;
          &lt;Price&gt;
              EUR.66.40
          &lt;/Price&gt;
      &lt;/Book&gt;   
  </code></pre>
  <p>USD_books.xml</p>
  <pre><code>&lt;Book&gt;
      &lt;Name&gt;
          Book3
      &lt;/Name&gt;
      &lt;Price&gt;
          USD.435.90
      &lt;/Price&gt;
  &lt;/Book&gt;
  </code></pre>
  <p>My code:</p>
  <pre><code>from xml.etree.cElementTree import iterparse
  
  
  
  for event, elem in context:
      if elem.tag == 'Book':
          Price = elem.find('Price').text
          title = Price.split('.')[0].strip()
          filename = format(title + &quot;_Books.xml&quot;)
          with open(filename, 'wb') as f:
              f.write(bytes(&quot;&lt;?xml version=\&quot;1.0\&quot; encoding=\&quot;UTF-8\&quot;?&gt;\n&quot;,'utf-8'))
              f.write(ET.tostring(elem))
  </code></pre>
  <p>I need the books with the same currency to be in one xml but I keep getting the error junk after document</p>