title: Python parse a binary document from xmlns and save locally
body: <p>So I have a response from a request call like this:</p>
  <pre><code>resourceType&quot;: &quot;Binary&quot;,
  &quot;id&quot;: &quot;07a6483f-732b-461e-86b6-edb665c45510&quot;,
  &quot;contentType&quot;: &quot;application/msword&quot;,
  &quot;content&quot;: &quot;UEsDBBQA.......
  </code></pre>
  <p>And it is showing in my code as:</p>
  <pre><code>b'&lt;Binary xmlns=&quot;http://hl7.org/fhir&quot;&gt;\r\n   &lt;id value=&quot;07a6483f-732b-461e-86b6-edb665c45510&quot;&gt;&lt;/id&gt;\r\n   &lt;contentType value=&quot;application/msword&quot;&gt;&lt;/contentType&gt;\r\n   &lt;content value=&quot;UEsDBBQ
  </code></pre>
  <p>I need to extract the content value and save as, in this case a word document.  I have tried solutions based on splitting, and using ElementTree but I cant seem to parse the content and save it as a word file.</p>
  <p>Right now just doing this:</p>
  <pre><code>with open('/tmp/metadata.doc', 'wb') as f:
      f.write(response.content
  </code></pre>
  <p>Results in a write of the whole piece, and Word opens like this:</p>
  <p><a href="https://i.stack.imgur.com/4q2iB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4q2iB.png" alt="enter image description here" /></a></p>
  <p>Any ideas?  Thanks in advance</p>