diff options
author | Martin v. Löwis <martin@v.loewis.de> | 2000-10-03 22:35:29 (GMT) |
---|---|---|
committer | Martin v. Löwis <martin@v.loewis.de> | 2000-10-03 22:35:29 (GMT) |
commit | cf0a1cc41705e27a8dd81536bb6a1b468bc22c59 (patch) | |
tree | 16f5c986e0f02a2361c4c7f0d18b995f4f7336da /Lib | |
parent | 1654b43ef79f81ce1ae6049f93db4a68f8408e3d (diff) | |
download | cpython-cf0a1cc41705e27a8dd81536bb6a1b468bc22c59.zip cpython-cf0a1cc41705e27a8dd81536bb6a1b468bc22c59.tar.gz cpython-cf0a1cc41705e27a8dd81536bb6a1b468bc22c59.tar.bz2 |
Support non-namespace elements in *ElementNS of XMLGenerator.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_sax.py | 6 | ||||
-rw-r--r-- | Lib/xml/sax/saxutils.py | 12 |
2 files changed, 15 insertions, 3 deletions
diff --git a/Lib/test/test_sax.py b/Lib/test/test_sax.py index 2b09cd6..1760eb2 100644 --- a/Lib/test/test_sax.py +++ b/Lib/test/test_sax.py @@ -112,11 +112,15 @@ def test_xmlgen_ns(): gen.startDocument() gen.startPrefixMapping("ns1", ns_uri) gen.startElementNS((ns_uri, "doc"), "ns1:doc", {}) + # add an unqualified name + gen.startElementNS((None, "udoc"), None, {}) + gen.endElementNS((None, "udoc"), None) gen.endElementNS((ns_uri, "doc"), "ns1:doc") gen.endPrefixMapping("ns1") gen.endDocument() - return result.getvalue() == start + ('<ns1:doc xmlns:ns1="%s"></ns1:doc>' % + return result.getvalue() == start + \ + ('<ns1:doc xmlns:ns1="%s"><udoc></udoc></ns1:doc>' % ns_uri) # ===== XMLFilterBase diff --git a/Lib/xml/sax/saxutils.py b/Lib/xml/sax/saxutils.py index a25b41f..892f34d 100644 --- a/Lib/xml/sax/saxutils.py +++ b/Lib/xml/sax/saxutils.py @@ -62,7 +62,12 @@ class XMLGenerator(handler.ContentHandler): self._out.write('</%s>' % name) def startElementNS(self, name, qname, attrs): - name = self._current_context[name[0]] + ":" + name[1] + if name[0] is None: + # if the name was not namespace-scoped, use the unqualified part + name = name[1] + else: + # else try to restore the original prefix from the namespace + name = self._current_context[name[0]] + ":" + name[1] self._out.write('<' + name) for pair in self._undeclared_ns_maps: @@ -75,7 +80,10 @@ class XMLGenerator(handler.ContentHandler): self._out.write('>') def endElementNS(self, name, qname): - name = self._current_context[name[0]] + ":" + name[1] + if name[0] is None: + name = name[1] + else: + name = self._current_context[name[0]] + ":" + name[1] self._out.write('</%s>' % name) def characters(self, content): |