MCPcopy Index your code
hub / github.com/python/cpython / startElementNS

Method startElementNS

Lib/xml/dom/pulldom.py:51–106  ·  view source on GitHub ↗
(self, name, tagName , attrs)

Source from the content-addressed store, hash-verified

49 self._current_context = self._ns_contexts.pop()
50
51 def startElementNS(self, name, tagName , attrs):
52 # Retrieve xml namespace declaration attributes.
53 xmlns_uri = 'http://www.w3.org/2000/xmlns/'
54 xmlns_attrs = getattr(self, '_xmlns_attrs', None)
55 if xmlns_attrs is not None:
56 for aname, value in xmlns_attrs:
57 attrs._attrs[(xmlns_uri, aname)] = value
58 self._xmlns_attrs = []
59 uri, localname = name
60 if uri:
61 # When using namespaces, the reader may or may not
62 # provide us with the original name. If not, create
63 # *a* valid tagName from the current context.
64 if tagName is None:
65 prefix = self._current_context[uri]
66 if prefix:
67 tagName = prefix + ":" + localname
68 else:
69 tagName = localname
70 if self.document:
71 node = self.document.createElementNS(uri, tagName)
72 else:
73 node = self.buildDocument(uri, tagName)
74 else:
75 # When the tagname is not prefixed, it just appears as
76 # localname
77 if self.document:
78 node = self.document.createElement(localname)
79 else:
80 node = self.buildDocument(None, localname)
81
82 for aname,value in attrs.items():
83 a_uri, a_localname = aname
84 if a_uri == xmlns_uri:
85 if a_localname == 'xmlns':
86 qname = a_localname
87 else:
88 qname = 'xmlns:' + a_localname
89 attr = self.document.createAttributeNS(a_uri, qname)
90 node.setAttributeNodeNS(attr)
91 elif a_uri:
92 prefix = self._current_context[a_uri]
93 if prefix:
94 qname = prefix + ":" + a_localname
95 else:
96 qname = a_localname
97 attr = self.document.createAttributeNS(a_uri, qname)
98 node.setAttributeNodeNS(attr)
99 else:
100 attr = self.document.createAttribute(a_localname)
101 node.setAttributeNode(attr)
102 attr.value = value
103
104 self.lastEvent[1] = [(START_ELEMENT, node), None]
105 self.lastEvent = self.lastEvent[1]
106 self.push(node)
107
108 def endElementNS(self, name, tagName):

Callers 1

startElementNSMethod · 0.45

Calls 8

buildDocumentMethod · 0.95
createElementNSMethod · 0.80
createElementMethod · 0.80
createAttributeNSMethod · 0.80
createAttributeMethod · 0.80
setAttributeNodeMethod · 0.80
itemsMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected