Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
cf0a1cc4
Commit
cf0a1cc4
authored
Oct 03, 2000
by
Martin v. Löwis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support non-namespace elements in *ElementNS of XMLGenerator.
parent
1654b43e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
3 deletions
+15
-3
Lib/test/test_sax.py
Lib/test/test_sax.py
+5
-1
Lib/xml/sax/saxutils.py
Lib/xml/sax/saxutils.py
+10
-2
No files found.
Lib/test/test_sax.py
View file @
cf0a1cc4
...
...
@@ -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
...
...
Lib/xml/sax/saxutils.py
View file @
cf0a1cc4
...
...
@@ -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
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment