Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.066 X-Spam-Evidence: '*H*': 0.87; '*S*': 0.00; 'none:': 0.07; '8bit%:30': 0.09; 'attributes': 0.09; 'wrote:': 0.18; 'trying': 0.19; '>>>': 0.22; 'import': 0.22; 'email addr:gmail.com>': 0.22; 'print': 0.22; '>>>': 0.24; 'skip:e 30': 0.24; "i've": 0.25; 'skip:" 40': 0.26; 'header:In-Reply-To:1': 0.27; 'tried': 0.27; 'idea': 0.28; 'xml': 0.29; '8bit%:3': 0.30; 'skip:& 60': 0.30; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; "skip:' 10": 0.31; '"",': 0.31; 'doc': 0.31; 'marc': 0.31; 'received:google.com': 0.35; 'doing': 0.36; 'hi,': 0.36; 'url:org': 0.36; 'skip:& 10': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'skip:x 10': 0.40; 'how': 0.40; 'it!': 0.67; 'jul': 0.74; 'desperately': 0.84; 'skip:) 10': 0.84; 'xmlns:xsi': 0.84; 'imagine': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=FtiOhxJeUtXd378J8kOEgI1lLpRhA8FeQolQYtNF/8A=; b=sGQ0bult7GQKMqo0OS2ITxfcNSPE3oD/RZ3exYvD619iAdAvcoBVDJMdJSzkt76VGd lwVWz/neBvD4oz7u6OfPqxiMwGPijPZytZUIyHWeDVqHR/LzN4H5o5ARucKTijWzTxoB EsJeBi6y1uQN3lvRIgsJWLvqsbKEJ/frqpRax3AxGO8tUiE+UpxxSDnkKij1l6rDwKI1 vgTdWgeWBXThMVJ/NwCElYyRy0AIj0q0QDK3L6fq6pvNqIrQJtgAR+R4CiNI/Sj0KTF9 0+4JSKLT65EULp1pU25TPP+H7xfcW0s1BYQtYJkenJWNXm1SYg0yxfIxunuqY0huKHLz Yo7w== X-Received: by 10.152.26.39 with SMTP id i7mr4587321lag.14.1406658975265; Tue, 29 Jul 2014 11:36:15 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: References: From: Marc Aymerich Date: Tue, 29 Jul 2014 20:35:55 +0200 Subject: Re: lxml and namespaces To: "comp.lang.python" Content-Type: multipart/alternative; boundary=089e0158bebe8a78dc04ff59505d X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 111 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1406658982 news.xs4all.nl 2961 [2001:888:2000:d::a6]:51575 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:75353 --089e0158bebe8a78dc04ff59505d Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Tue, Jul 29, 2014 at 8:19 PM, Marc Aymerich wrote: > Hi, I'm desperately trying to construct an XML with the following documen= t > declaration: > > xmlns:xsi=3D=E2=80=9Dhttp://www.w3.org/2001/XMLSchema-instance=E2= =80=9D> > > I'm using LXML, and what I'm doing is this > > >>> from lxml import etree > >>> from lxml.builder import E > >>> doc =3D E.Document( > ... { > ... 'xmlns': "urn:iso:std:iso:20022:tech:xsd:pain.008.001.02", > ... '{xmlns}xsi': "http://www.w3.org/2001/XMLSchema-instance", > ... } > ... ) > >>> print etree.tostring(doc) > http://www.w3.org/2001/XMLSchema-instance" > xmlns=3D"urn:iso:std:iso:20022:tech:xsd:pain.008.001.02"/> > > > I've tried everything I can imagine and this is the best I can do :( > > Any idea on how to get the xmlns and xmlns:xsi attributes correctly? > Got it! xml =3D lxml.builder.ElementMaker( nsmap =3D { None: "urn:iso:std:iso:20022:tech:xsd:pain.008.001.02", 'xsi': "http://www.w3.org/2001/XMLSchema-instance", } ) doc =3D xml.Document() --=20 Marc --089e0158bebe8a78dc04ff59505d Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable



On Tue, Jul 29, 2014 at 8:19 PM, Marc Aymerich <glice= rinu@gmail.com> wrote:
Hi, I'm desperately trying to constru= ct an XML with the following document declaration:

<Document xmlns=3D=E2=80=9Durn:iso:std:iso:20022:tec= h:xsd:pain.008.001.02=E2=80=9D
=C2=A0 =C2=A0 =C2=A0 =C2=A0 xmlns:= xsi=3D=E2=80=9Dhttp://www.w3.org/2001/XMLSchema-instance=E2=80=9D>

I'm using LXML, and what I'm doing is this

>>> from lxml import etree
>= ;>> from lxml.builder import E
>>> doc =3D E.Docum= ent(
... =C2=A0 =C2=A0 {
... =C2=A0 =C2=A0 =C2=A0 =C2=A0 'xml= ns': "urn:iso:std:iso:20022:tech:xsd:pain.008.001.02",
<= div>... =C2=A0 =C2=A0 =C2=A0 =C2=A0 '{xmlns}xsi': "http://www.w3.= org/2001/XMLSchema-instance",
... =C2=A0 =C2=A0 }
... )
>>> print etree= .tostring(doc)
<Document xmlns:ns0=3D"xmlns" ns0:xsi= =3D"http://www.w3.org/2001/XMLSchema-instance"
=C2=A0 =C2=A0 =C2=A0 =C2=A0 xmlns=3D"urn:iso:std:iso:20022:tech:x= sd:pain.008.001.02"/>


I've tried everything I can imagine and this is the best I can do :(

Any idea on how to get the xmlns and xmlns:xsi attributes correctly?


Got it!
xml =3D lxml.builder.ElementMaker(
=C2=A0 =C2=A0 =C2=A0nsm= ap =3D {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0None: "urn:iso:std:iso:20022:te= ch:xsd:pain.008.001.02",
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0&= #39;xsi': "h= ttp://www.w3.org/2001/XMLSchema-instance",
=C2=A0 =C2=A0 =C2=A0}
)
doc =3D xml.Document()=C2= =A0


--
Marc
--089e0158bebe8a78dc04ff59505d--