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

Method renameNode

Lib/xml/dom/minidom.py:1843–1894  ·  view source on GitHub ↗
(self, n, namespaceURI, name)

Source from the content-addressed store, hash-verified

1841 # DOM Level 3 (WD 9 April 2002)
1842
1843 def renameNode(self, n, namespaceURI, name):
1844 if n.ownerDocument is not self:
1845 raise xml.dom.WrongDocumentErr(
1846 "cannot rename nodes from other documents;\n"
1847 "expected %s,\nfound %s" % (self, n.ownerDocument))
1848 if n.nodeType not in (Node.ELEMENT_NODE, Node.ATTRIBUTE_NODE):
1849 raise xml.dom.NotSupportedErr(
1850 "renameNode() only applies to element and attribute nodes")
1851 if namespaceURI != EMPTY_NAMESPACE:
1852 if ':' in name:
1853 prefix, localName = name.split(':', 1)
1854 if ( prefix == "xmlns"
1855 and namespaceURI != xml.dom.XMLNS_NAMESPACE):
1856 raise xml.dom.NamespaceErr(
1857 "illegal use of 'xmlns' prefix")
1858 else:
1859 if ( name == "xmlns"
1860 and namespaceURI != xml.dom.XMLNS_NAMESPACE
1861 and n.nodeType == Node.ATTRIBUTE_NODE):
1862 raise xml.dom.NamespaceErr(
1863 "illegal use of the 'xmlns' attribute")
1864 prefix = None
1865 localName = name
1866 else:
1867 prefix = None
1868 localName = None
1869 if n.nodeType == Node.ATTRIBUTE_NODE:
1870 element = n.ownerElement
1871 if element is not None:
1872 is_id = n._is_id
1873 element.removeAttributeNode(n)
1874 else:
1875 element = None
1876 n.prefix = prefix
1877 n._localName = localName
1878 n.namespaceURI = namespaceURI
1879 n.nodeName = name
1880 if n.nodeType == Node.ELEMENT_NODE:
1881 n.tagName = name
1882 else:
1883 # attribute node
1884 n.name = name
1885 if element is not None:
1886 element.setAttributeNode(n)
1887 if is_id:
1888 element.setIdAttributeNode(n)
1889 # It's not clear from a semantic perspective whether we should
1890 # call the user data handlers for the NODE_RENAMED event since
1891 # we're re-using the existing node. The draft spec has been
1892 # interpreted as meaning "no, don't call the handler unless a
1893 # new node is created."
1894 return n
1895
1896defproperty(Document, "documentElement",
1897 doc="Top-level element of this document.")

Callers 5

testRenameAttributeMethod · 0.80
testRenameElementMethod · 0.80
testSetIdAttributeMethod · 0.80
testSetIdAttributeNSMethod · 0.80

Calls 4

removeAttributeNodeMethod · 0.80
setAttributeNodeMethod · 0.80
setIdAttributeNodeMethod · 0.80
splitMethod · 0.45

Tested by 5

testRenameAttributeMethod · 0.64
testRenameElementMethod · 0.64
testSetIdAttributeMethod · 0.64
testSetIdAttributeNSMethod · 0.64