[lxml-dev] xpath on newly created elements
Doug Winter
doug at isotoma.com
Sun Jul 8 10:26:34 CEST 2007
Stefan Behnel wrote:
> Well, you can currently create them this way, but it doesn't give you what you
> want. Maybe we should catch the case where ':' is contained in a tag name and
> raise an exception instead (it won't give you well-formed XML anyway). That
> way, it would be clear that this can't work.
>
> When you create elements with namespaces, use the Clark notation.
Thanks for the clarification. What threw me is that serialising a tag
with a colon in it works fine, and this all feels quite natural:
>>> nsmap = {'test': 'http://test.com'}
>>> e = etree.Element('test:foo', nsmap=nsmap)
>>> e2 = etree.fromstring(etree.tostring(e))
>>> e.xpath("/test:foo", nsmap)
[]
>>> e2.xpath("/test:foo", nsmap)
[<Element {http://test.com}foo at b793d5a4>]
I'd expect the round trip to produce something identical, which I guess
is where I got confused. I think it may be worth raising an exception
on tags with colons, since it is a bit surprising.
Cheers,
Doug.
--
Isotoma, Open Source Software Consulting - http://www.isotoma.com
Tel: 01904 567349, Mobile: 07879 423002, Fax: 020 79006980
Postal Address: Tower House, Fishergate, York, YO10 4UA, UK
Registered in England. Company No 5171172. VAT GB843570325.
Registered Office: 19a Goodge Street, London, W1T 2PH
More information about the lxml-dev
mailing list