How to construct element with non-default XML namespace?

8 views
Skip to first unread message

Felix Schwarz

unread,
Sep 10, 2013, 11:20:27 AM9/10/13
to gen...@googlegroups.com

I want to build an Element (genshi.builder) which renders exactly to this string
u'<ns1:foo xmlns:ns1="http://example.com"/>'

but the closest I can get to is:
Element('http://example.com}ns1:foo')
which results in
u'<ns1:foo xmlns="http://example.com"/>'

Is it possible to specify different namespaces in Genshi's Element?

fs

Simon Cross

unread,
Sep 15, 2013, 5:51:50 AM9/15/13
to gen...@googlegroups.com
Element("ns1:foo", **{"xmlns:ns1": "http://example.com"})

Seems to do what you want. It's a bit clumsy but maybe that's okay.

Felix Schwarz

unread,
Sep 17, 2013, 4:46:32 AM9/17/13
to gen...@googlegroups.com
Am 15.09.2013 11:51, schrieb Simon Cross:
> Element("ns1:foo", **{"xmlns:ns1": "http://example.com"})
>
> Seems to do what you want. It's a bit clumsy but maybe that's okay.

Thanks, that did the trick indeed. Stupid me.

fs


Reply all
Reply to author
Forward
0 new messages