<div dir="ltr"><div><br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Jul 29, 2014 at 8:19 PM, Marc Aymerich <span dir="ltr"><<a href="mailto:glicerinu@gmail.com" target="_blank">glicerinu@gmail.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr">Hi, I'm desperately trying to construct an XML with the following document declaration:<div>

<br></div><div><div><Document xmlns=”urn:iso:std:iso:20022:tech:xsd:pain.008.001.02”</div><div>        xmlns:xsi=”<a href="http://www.w3.org/2001/XMLSchema-instance" target="_blank">http://www.w3.org/2001/XMLSchema-instance</a>”></div>


<div><br></div><div>I'm using LXML, and what I'm doing is this</div><div><br></div><div><div>>>> from lxml import etree</div><div>>>> from lxml.builder import E</div><div>>>> doc = E.Document(</div>


<div>...     {</div><div>...         'xmlns': "urn:iso:std:iso:20022:tech:xsd:pain.008.001.02",</div><div>...         '{xmlns}xsi': "<a href="http://www.w3.org/2001/XMLSchema-instance" target="_blank">http://www.w3.org/2001/XMLSchema-instance</a>",</div>


<div>...     }</div><div>... )</div><div>>>> print etree.tostring(doc)</div><div><Document xmlns:ns0="xmlns" ns0:xsi="<a href="http://www.w3.org/2001/XMLSchema-instance" target="_blank">http://www.w3.org/2001/XMLSchema-instance</a>"</div>


<div>        xmlns="urn:iso:std:iso:20022:tech:xsd:pain.008.001.02"/></div></div><div><br></div><div><br></div><div>I've tried everything I can imagine and this is the best I can do :(</div><div><br></div>


<div>Any idea on how to get the xmlns and xmlns:xsi attributes correctly?</div></div></div></blockquote><div><br></div><div><br></div><div>Got it!</div><div>xml = lxml.builder.ElementMaker(</div><div>     nsmap = {</div>

<div>         None: "urn:iso:std:iso:20022:tech:xsd:pain.008.001.02",</div><div>         'xsi': "<a href="http://www.w3.org/2001/XMLSchema-instance">http://www.w3.org/2001/XMLSchema-instance</a>",</div>

<div>     }</div><div>)</div><div>doc = xml.Document() </div></div><br clear="all"><div><br></div>-- <br>Marc
</div></div>