Python2.5 中 由cloneNode(xml.dom.minidom)产生的xml Node元素的tagName问题

Python2.5 中

由cloneNode(xml.dom.minidom)产生的xml Node元素的tagName

与 最开始的原始节点建立时的tagName相同,

不管你中间的克隆节点的tagName改变成什么,

也不管原始节点的tagName改变成什么!

 

下面是测试代码:

  1. #!/usr/bin/env python
  2. #coding:UTF-8
  3. from xml.dom import minidom
  4.  
  5. xmlStr = '<?xml version="1.0" encoding="UTF-8"?><test><oldTagName/></test>'
  6. xmlDoc = minidom.parseString(xmlStr)
  7. firstNode = xmlDoc.firstChild
  8.  
  9. originalNode = firstNode.firstChild
  10. originalNode.setAttribute('name','originalNode')
  11. print 'This is original Node.'
  12. print originalNode.toxml()
  13. print '-------------------------------------------'
  14.  
  15. originalNode.tagName = 'original_Changed'
  16. print 'I give the originalNode a new tagName.'
  17. print originalNode.toxml()
  18. print '-------------------------------------------'
  19.  
  20. cloneNode = originalNode.cloneNode(0)
  21. cloneNode.setAttribute('name','cloneNode')
  22. print 'This is clone Node from original Node, The tagName is the same as the old tagName of original Node!!!.'
  23. print cloneNode.toxml()
  24. print '-------------------------------------------'
  25.  
  26. cloneNode.tagName = 'isChanged'
  27. print 'I give cloneNode a new tagName.'
  28. print cloneNode.toxml()
  29. print '-------------------------------------------'
  30.  
  31. cloneCloneNode = cloneNode.cloneNode(0)
  32. cloneCloneNode.setAttribute('name','cloneCloneNode')
  33. print 'This is clone Node from colne Node, The tagName is the same as the old tagName of original Node!!!.'
  34. print cloneCloneNode.toxml()
  35. print '-------------------------------------------'
  36.  
  37. cloneCloneNode.tagName = 'isChanged_too'
  38. print 'I give the cloneCloneNode a new tagName.'
  39. print cloneCloneNode.toxml()
  40. print '-------------------------------------------'
  41.  
  42. originalNode.tagName = 'flow_Changed'
  43. print 'I give the originalNode a new tagName.'
  44. print originalNode.toxml()
  45. print '-------------------------------------------'
  46.  
  47. CCCNode = cloneCloneNode.cloneNode(0)
  48. cloneNode.setAttribute('name','CCCNode')
  49. print 'This is clone Node from cloneCloneNode, The tagName is the same as the old tagName of original Node!!!.'
  50. print CCCNode.toxml()
  51. print '-------------------------------------------'
  52.  
  53. NewCloneNode = originalNode.cloneNode(0)
  54. NewCloneNode.setAttribute('name','NewCloneNode')
  55. print 'This is noe clone Node from originalNode, The tagName is the same as the old tagName of original Node!!!.'
  56. print NewCloneNode.toxml()
  57. print '-------------------------------------------'
  58.  
  59. print 'so, The tagName of the clone clone Node == The the old tagName  of original Node!!!!!!!!!!'
  60. 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