Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2c8a89c

Browse files
committed
minidom: access attribute value before printing it
correct order of constructor args in createAttributeNS pulldom: use symbolic names for uri and localnames correct usage of createAttribute and setAttributeNode signatures.
1 parent 80670bc commit 2c8a89c

2 files changed

Lines changed: 14 additions & 12 deletions

File tree

Lib/xml/dom/minidom.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ def writexml(self, writer):
331331

332332
for a_name in a_names:
333333
writer.write(" %s=\"" % a_name)
334-
_write_data(writer, self._get_attributes()[a_name])
334+
_write_data(writer, self._get_attributes()[a_name].value)
335335
writer.write("\"")
336336
if self.childNodes:
337337
writer.write(">")
@@ -429,7 +429,7 @@ def createElementNS(self, namespaceURI, qualifiedName):
429429

430430
def createAttributeNS(self, namespaceURI, qualifiedName):
431431
prefix,localName = _nssplit(qualifiedName)
432-
return Attr(namespaceURI, qualifiedName, localName, prefix)
432+
return Attr(qualifiedName, namespaceURI, localName, prefix)
433433

434434
def getElementsByTagNameNS(self, namespaceURI, localName):
435435
_getElementsByTagNameNSHelper(self, namespaceURI, localName)

Lib/xml/dom/pulldom.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,26 +27,28 @@ def endPrefixMapping(self, prefix):
2727
del self._ns_contexts[-1]
2828

2929
def startElementNS(self, name, tagName , attrs):
30-
if name[0]:
30+
uri,localname = name
31+
if uri:
3132
# When using namespaces, the reader may or may not
3233
# provide us with the original name. If not, create
3334
# *a* valid tagName from the current context.
3435
if tagName is None:
35-
tagName = self._current_context[name[0]] + ":" + name[1]
36-
node = self.document.createElementNS(name[0], tagName)
36+
tagName = self._current_context[uri] + ":" + localname
37+
node = self.document.createElementNS(uri, tagName)
3738
else:
3839
# When the tagname is not prefixed, it just appears as
39-
# name[1]
40-
node = self.document.createElement(name[1])
40+
# localname
41+
node = self.document.createElement(localname)
4142

4243
for aname,value in attrs.items():
43-
if aname[0]:
44-
qname = self._current_context[name[0]] + ":" + aname[1]
45-
attr = self.document.createAttributeNS(name[0], qname)
44+
a_uri, a_localname = aname
45+
if a_uri:
46+
qname = self._current_context[a_uri] + ":" + a_localname
47+
attr = self.document.createAttributeNS(a_uri, qname)
4648
else:
47-
attr = self.document.createAttribute(name[0], name[1])
49+
attr = self.document.createAttribute(a_localname)
4850
attr.value = value
49-
node.setAttributeNode(qname, attr)
51+
node.setAttributeNode(attr)
5052

5153
parent = self.curNode
5254
node.parentNode = parent

0 commit comments

Comments
 (0)