Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #75353 > unrolled thread

Re: lxml and namespaces

Started byMarc Aymerich <glicerinu@gmail.com>
First post2014-07-29 20:35 +0200
Last post2014-07-29 21:21 +0200
Articles 2 — 2 participants

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: lxml and namespaces Marc Aymerich <glicerinu@gmail.com> - 2014-07-29 20:35 +0200
    Re: lxml and namespaces Irmen de Jong <irmen.NOSPAM@xs4all.nl> - 2014-07-29 21:21 +0200

#75353 — Re: lxml and namespaces

FromMarc Aymerich <glicerinu@gmail.com>
Date2014-07-29 20:35 +0200
SubjectRe: lxml and namespaces
Message-ID<mailman.12420.1406658982.18130.python-list@python.org>

[Multipart message — attachments visible in raw view] — view raw

On Tue, Jul 29, 2014 at 8:19 PM, Marc Aymerich <glicerinu@gmail.com> wrote:

> Hi, I'm desperately trying to construct an XML with the following document
> declaration:
>
> <Document xmlns=”urn:iso:std:iso:20022:tech:xsd:pain.008.001.02”
>         xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”>
>
> I'm using LXML, and what I'm doing is this
>
> >>> from lxml import etree
> >>> from lxml.builder import E
> >>> doc = 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)
> <Document xmlns:ns0="xmlns" ns0:xsi="
> http://www.w3.org/2001/XMLSchema-instance"
>         xmlns="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 = lxml.builder.ElementMaker(
     nsmap = {
         None: "urn:iso:std:iso:20022:tech:xsd:pain.008.001.02",
         'xsi': "http://www.w3.org/2001/XMLSchema-instance",
     }
)
doc = xml.Document()


-- 
Marc

[toc] | [next] | [standalone]


#75354

FromIrmen de Jong <irmen.NOSPAM@xs4all.nl>
Date2014-07-29 21:21 +0200
Message-ID<53d7f433$0$2902$e4fe514c@news.xs4all.nl>
In reply to#75353
On 29-7-2014 20:35, Marc Aymerich wrote:


> Got it!
> xml = lxml.builder.ElementMaker(
>      nsmap = {
>          None: "urn:iso:std:iso:20022:tech:xsd:pain.008.001.02",
>          'xsi': "http://www.w3.org/2001/XMLSchema-instance",
>      }
> )
> doc = xml.Document()


Thanks for taking the time to actually post the solution you came up with yourself!

Irmen

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web