[lxml-dev] xmlns / xmlns:xmlns inconsistency
jholg at gmx.de
jholg at gmx.de
Fri Sep 12 09:33:06 CEST 2008
Hi,
> Aaron Brady wrote:
> > I tried to set a 'xmlns' attribute of a node. 'etree.tostring'
> > produced an attribute name of 'xmlns:xmlns' instead.
>
> Interesting. I think we should raise a descriptive error when someone
> tries to
> set an attribute with that name.
>
>
> > Target:
> >
> > <Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
>
> Use
>
> root = etree.Element(
> '{urn:schemas-microsoft-com:office:spreadsheet}Workbook' )
>
> and read the docs at
>
> http://codespeak.net/lxml/tutorial.html#namespaces
>
>
While I can't see the usecase for it, lxml doesn't allow to use two
different ns-prefixes for the
same namespace through the API, but it does when parsing:
>>> root = etree.fromstring('<root xmlns:foo="/foo/bar/namespace"
xmlns="/foo/bar/namespace"/>')
>>> print etree.tostring(root)
<root xmlns:foo="/foo/bar/namespace" xmlns="/foo/bar/namespace"/>
>>> root.nsmap
{'foo': '/foo/bar/namespace', None: '/foo/bar/namespace'}
>>> root2 = etree.Element("root", nsmap=root.nsmap)
>>> print etree.tostring(root2)
<root xmlns:foo="/foo/bar/namespace"/>
>>>
Holger
--
GMX startet ShortView.de. Hier findest Du Leute mit Deinen Interessen!
Jetzt dabei sein: http://www.shortview.de/wasistshortview.php?mc=sv_ext_mf@gmx
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://codespeak.net/pipermail/lxml-dev/attachments/20080912/7f31c214/attachment.htm
More information about the lxml-dev
mailing list