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
984158d2
Commit
984158d2
authored
Jul 18, 2001
by
Martin v. Löwis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Patch #432117: Record namespaces in the DOM tree using the DOM xmlns prefix.
parent
b311ad5b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
1 deletion
+18
-1
Lib/xml/dom/pulldom.py
Lib/xml/dom/pulldom.py
+18
-1
No files found.
Lib/xml/dom/pulldom.py
View file @
984158d2
...
...
@@ -44,6 +44,9 @@ class PullDOM(xml.sax.ContentHandler):
self
.
_locator
=
locator
def
startPrefixMapping
(
self
,
prefix
,
uri
):
if
not
hasattr
(
self
,
'_xmlns_attrs'
):
self
.
_xmlns_attrs
=
[]
self
.
_xmlns_attrs
.
append
((
prefix
or
'xmlns'
,
uri
))
self
.
_ns_contexts
.
append
(
self
.
_current_context
.
copy
())
self
.
_current_context
[
uri
]
=
prefix
or
''
...
...
@@ -51,6 +54,13 @@ class PullDOM(xml.sax.ContentHandler):
self
.
_current_context
=
self
.
_ns_contexts
.
pop
()
def
startElementNS
(
self
,
name
,
tagName
,
attrs
):
# Retrieve xml namespace declaration attributes.
xmlns_uri
=
'http://www.w3.org/2000/xmlns/'
xmlns_attrs
=
getattr
(
self
,
'_xmlns_attrs'
,
None
)
if
xmlns_attrs
is
not
None
:
for
aname
,
value
in
xmlns_attrs
:
attrs
.
_attrs
[(
xmlns_uri
,
aname
)]
=
value
self
.
_xmlns_attrs
=
[]
uri
,
localname
=
name
if
uri
:
# When using namespaces, the reader may or may not
...
...
@@ -76,7 +86,14 @@ class PullDOM(xml.sax.ContentHandler):
for
aname
,
value
in
attrs
.
items
():
a_uri
,
a_localname
=
aname
if
a_uri
:
if
a_uri
==
xmlns_uri
:
if
a_localname
==
'xmlns'
:
qname
=
a_localname
else
:
qname
=
'xmlns:'
+
a_localname
attr
=
self
.
document
.
createAttributeNS
(
a_uri
,
qname
)
node
.
setAttributeNodeNS
(
attr
)
elif
a_uri
:
prefix
=
self
.
_current_context
[
a_uri
]
if
prefix
:
qname
=
prefix
+
":"
+
a_localname
...
...
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