Python2.5 中 由cloneNode(xml.dom.minidom)产生的xml Node元素的tagName问题
Python2.5 中
由cloneNode(xml.dom.minidom)产生的xml Node元素的tagName
与 最开始的原始节点建立时的tagName相同,
不管你中间的克隆节点的tagName改变成什么,
也不管原始节点的tagName改变成什么!
下面是测试代码:
-
#!/usr/bin/env python
-
#coding:UTF-8
-
from xml.dom import minidom
-
-
xmlStr = '<?xml version="1.0" encoding="UTF-8"?><test><oldTagName/></test>'
-
xmlDoc = minidom.parseString(xmlStr)
-
firstNode = xmlDoc.firstChild
-
-
originalNode = firstNode.firstChild
-
originalNode.setAttribute('name','originalNode')
-
print 'This is original Node.'
-
print originalNode.toxml()
-
print '-------------------------------------------'
-
-
originalNode.tagName = 'original_Changed'
-
print 'I give the originalNode a new tagName.'
-
print originalNode.toxml()
-
print '-------------------------------------------'
-
-
cloneNode = originalNode.cloneNode(0)
-
cloneNode.setAttribute('name','cloneNode')
-
print 'This is clone Node from original Node, The tagName is the same as the old tagName of original Node!!!.'
-
print cloneNode.toxml()
-
print '-------------------------------------------'
-
-
cloneNode.tagName = 'isChanged'
-
print 'I give cloneNode a new tagName.'
-
print cloneNode.toxml()
-
print '-------------------------------------------'
-
-
cloneCloneNode = cloneNode.cloneNode(0)
-
cloneCloneNode.setAttribute('name','cloneCloneNode')
-
print 'This is clone Node from colne Node, The tagName is the same as the old tagName of original Node!!!.'
-
print cloneCloneNode.toxml()
-
print '-------------------------------------------'
-
-
cloneCloneNode.tagName = 'isChanged_too'
-
print 'I give the cloneCloneNode a new tagName.'
-
print cloneCloneNode.toxml()
-
print '-------------------------------------------'
-
-
originalNode.tagName = 'flow_Changed'
-
print 'I give the originalNode a new tagName.'
-
print originalNode.toxml()
-
print '-------------------------------------------'
-
-
CCCNode = cloneCloneNode.cloneNode(0)
-
cloneNode.setAttribute('name','CCCNode')
-
print 'This is clone Node from cloneCloneNode, The tagName is the same as the old tagName of original Node!!!.'
-
print CCCNode.toxml()
-
print '-------------------------------------------'
-
-
NewCloneNode = originalNode.cloneNode(0)
-
NewCloneNode.setAttribute('name','NewCloneNode')
-
print 'This is noe clone Node from originalNode, The tagName is the same as the old tagName of original Node!!!.'
-
print NewCloneNode.toxml()
-
print '-------------------------------------------'
-
-
print 'so, The tagName of the clone clone Node == The the old tagName of original Node!!!!!!!!!!'
-
print 'The attributes of the clone clone Node == The attributes of the clone Node'
结果:
This is original Node.
<oldTagName name="originalNode"/>
-------------------------------------------
I give the originalNode a new tagName.
<original_Changed name="originalNode"/>
-------------------------------------------
This is clone Node from original Node, The tagName is the same as the old tagName of original Node!!!.
<oldTagName name="cloneNode"/>
-------------------------------------------
I give cloneNode a new tagName.
<isChanged name="cloneNode"/>
-------------------------------------------
This is clone Node from colne Node, The tagName is the same as the old tagName of original Node!!!.
<oldTagName name="cloneCloneNode"/>
-------------------------------------------
I give the cloneCloneNode a new tagName.
<isChanged_too name="cloneCloneNode"/>
-------------------------------------------
I give the originalNode a new tagName.
<flow_Changed name="originalNode"/>
-------------------------------------------
This is clone Node from cloneCloneNode, The tagName is the same as the old tagName of original Node!!!.
<oldTagName name="cloneCloneNode"/>
-------------------------------------------
This is noe clone Node from originalNode, The tagName is the same as the old tagName of original Node!!!.
<oldTagName name="NewCloneNode"/>
-------------------------------------------
so, The tagName of the clone clone Node == The the old tagName of original Node!!!!!!!!!!
The attributes of the clone clone Node == The attributes of the clone Node