diff options
| author | scoder <none@none> | 2010-03-26 06:45:19 +0100 |
|---|---|---|
| committer | scoder <none@none> | 2010-03-26 06:45:19 +0100 |
| commit | b9706d912a88dcf84cd8bc38b70ed7b157e9df9a (patch) | |
| tree | 815c39fc833fd92b754eef409cf774bf1de323d6 /doc/tutorial.txt | |
| parent | c0b410f4c464d5377395d53f7723c36cf628def3 (diff) | |
| download | python-lxml-b9706d912a88dcf84cd8bc38b70ed7b157e9df9a.tar.gz | |
[svn r4383] r5532@lenny: sbehnel | 2010-03-26 06:45:12 +0100
doc updates
--HG--
branch : trunk
Diffstat (limited to 'doc/tutorial.txt')
| -rw-r--r-- | doc/tutorial.txt | 38 |
1 files changed, 33 insertions, 5 deletions
diff --git a/doc/tutorial.txt b/doc/tutorial.txt index 9d0b1137..010938c8 100644 --- a/doc/tutorial.txt +++ b/doc/tutorial.txt @@ -1013,13 +1013,41 @@ to the Element factory, e.g. to define the default namespace: <body>Hello World</body> </html> +lxml.etree allows you to look up the current namespaces defined for a +node through the ``.nsmap`` property: + +.. sourcecode:: pycon + + >>> xhtml.nsmap + {None: 'http://www.w3.org/1999/xhtml'} + +Note, however, that this includes all prefixes known in the context of +an Element, not only those that it defines itself. + +.. sourcecode:: pycon + + >>> root = etree.Element('root', nsmap={'a': 'http://a.b/c'}) + >>> child = etree.SubElement(root, 'child', + ... nsmap={'b': 'http://b.c/d'}) + >>> len(root.nsmap) + 1 + >>> len(child.nsmap) + 2 + >>> child.nsmap['a'] + 'http://a.b/c' + >>> child.nsmap['b'] + 'http://b.c/d' + +Therefore, modifying the returned dict cannot have any meaningful +impact on the Element. Any changes to it are ignored. + Namespaces on attributes work alike, but since version 2.3, lxml.etree will make sure that the attribute uses a prefixed namespace -declaration. This is because unprefixed attribute names are not -considered being in a namespace by the XML namespace specification -(`section 6.2`_), so they may end up loosing their namespace on a -serialise-parse roundtrip, even if they appear in a namespaced -element. +declaration if one was defined. This is because unprefixed attribute +names are not considered being in a namespace by the XML namespace +specification (`section 6.2`_), so they may end up loosing their +namespace on a serialise-parse roundtrip, even if they appear in a +namespaced element. .. sourcecode:: pycon |
