title: Parse xsi:type in XML with ElementTree in Python
body: <p>I'm trying to connect to a RESTful API and I'm hacing problems when building the XML request, for that I'm using Elementree library.</p>
  
  <p>I have an example of the XML I have to send in the request. From that example a build a model and then write the different attributes by code. But  the output XML is not exactly like the example I was given and I'm unable to connect to the API.</p>
  
  <p>This is the example I have: </p>
  
  <pre><code>  &lt;soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
      &lt;soap:Body&gt;
        &lt;GetLoc xmlns="http://abc/Getloc"&gt;
          &lt;request&gt;
            &lt;Access&gt;
              &lt;string xmlns="http://bcd/Arrays"&gt;&lt;/string&gt;
            &lt;/Access&gt;
            &lt;Details xsi:type="Request"&gt;
              &lt;Postcode &gt;&lt;/Postcode &gt;
            &lt;/Details&gt;
            &lt;UserConsent&gt;Yes&lt;/UserConsent&gt;
          &lt;/request&gt;
        &lt;/GetLoc&gt;
      &lt;/soap:Body&gt;
    &lt;/soap:Envelope&gt;
  </code></pre>
  
  <p>This is my code:</p>
  
  <pre><code>tree = ET.parse('model.xml')
  root = tree.getroot()
  ns = {'loc':'http://abc/Getloc',\
          'arr':http://bcd/Arrays',\
          'soapenv':'http://schemas.xmlsoap.org/soap/envelope/', \
          'xsi':"http://www.w3.org/2001/XMLSchema-instance", \
           xsd': "http://www.w3.org/2001/XMLSchema"}
  
  tree.find('.//arr:string', ns).text = 'THC'
  tree.find('.//Postcode ', ns).text = '15478'
  </code></pre>
  
  <p>This is the output XML (SOAP):</p>
  
  <pre><code>  &lt;ns0:Envelope xmlns:ns0="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://abc/Getloc" xmlns:ns2="http://bcd/Arrays" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
      &lt;ns0:Body&gt;
        &lt;ns1:GetLoc &gt;
          &lt;ns1:request&gt;
            &lt;ns1:Access&gt;
              &lt;ns2:string&gt;THC&lt;/ns2:string&gt;
            &lt;/ns1:Access&gt;
            &lt;ns1:Details xsi:type="Request"&gt;
              &lt;ns1:Postcode &gt;15478&lt;/ns1:Postcode &gt;
            &lt;/ns1:Details&gt;
            &lt;ns1:UserConsent&gt;Yes&lt;/ns1:UserConsent&gt;
          &lt;/ns1:request&gt;
        &lt;/ns1:GetLoc &gt;
      &lt;/ns0:Body&gt;
    &lt;/ns0:Envelope&gt;
  </code></pre>
  
  <p>With the example (first above) I have no problem when connecting to the API. However with the second one I get and error:</p>
  
  <pre><code> " status="Service Not Found.  The request may have been sent to an invalid URL, or intended for an unsupported operation." xmlns:l7="http://www.layer7tech.com/ws/policy/fault"/&gt;"
  </code></pre>
  
  <p>Both XML are sent to the same URL with the same headers and auth. I see both XML equivalent so I was expecting same behavior. I don't understand why it isn't working. </p>
  
  <p>EDIT: The output XML needs to be like</p>
  
  <pre><code>&lt;ns0:Envelope xmlns:ns0="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://abc/Getloc" xmlns:ns2="http://bcd/Arrays" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
          &lt;ns0:Body&gt;
            &lt;ns1:GetLoc &gt;
              &lt;ns1:request&gt;
                &lt;ns1:Access&gt;
                  &lt;ns2:string&gt;THC&lt;/ns2:string&gt;
                &lt;/ns1:Access&gt;
                &lt;ns1:Details xsi:type="ns1:Request"&gt;
                  &lt;ns1:Postcode &gt;15478&lt;/ns1:Postcode &gt;
                &lt;/ns1:Details&gt;
                &lt;ns1:UserConsent&gt;Yes&lt;/ns1:UserConsent&gt;
              &lt;/ns1:request&gt;
            &lt;/ns1:GetLoc &gt;
          &lt;/ns0:Body&gt;
        &lt;/ns0:Envelope&gt;
  </code></pre>
  
  <p>But I don't know hoy to change the code to get: <strong>xsi:type="ns1:Request"</strong></p>