根据来自这里的信息:
由于 .tagName 是只读的,因此您必须创建一个具有合适名称的新节点,克隆要更改的节点,然后用新节点替换旧节点。在代码中:
Dim sFSpec : sFSpec = resolvePath( "..\data\00.xml" )
WScript.Echo goFS.OpenTextFile(sFSpec).ReadAll()
Dim oXDoc : Set oXDoc = CreateObject( "Msxml2.DOMDocument" )
oXDoc.setProperty "SelectionLanguage", "XPath"
oXDoc.async = False
oXDoc.load sFSpec
If 0 = oXDoc.ParseError Then
WScript.Echo sFSpec, "looks ok"
Dim sXPath, ndFnd
sXPath = "/ICOSTx"
Set ndFnd = oXDoc.selectSingleNode( sXPath )
If ndFnd Is Nothing Then
WScript.Echo "|", sXPath, "| not found"
Else
WScript.Echo "found |" & ndFnd.tagName & "|"
On Error Resume Next
ndFnd.tagName = "ICOS_ORDER_TX"
WScript.Echo "** Bingo:", Err.Description
On Error Goto 0
Dim ndParent : Set ndParent = ndFnd.parentNode
Dim ndNew : Set ndNew = oXDoc.createElement("ICOS_ORDER_TX")
ndNew.appendChild ndFnd.firstChild.cloneNode(True)
ndParent.removeChild ndFnd
ndParent.appendChild ndNew
sFSpec = resolvePath( "..\data\02.xml" )
oXDoc.save sFSpec
WScript.Echo goFS.OpenTextFile(sFSpec).ReadAll()
End If
Else
WScript.Echo oXDoc.ParseError.Reason
End If
输出:
<ICOSTx SOURCETYPE="XX">
<HEADER>
<ID>49909171</ID>
<EMP>P9004952</EMP>
<STARTDT>10/04/2012 14:23:04</STARTDT>
<TOTAL>5849.59</TOTAL>
<CNP>1</CNP>
</HEADER>
</ICOSTx>
E:\trials\SoTrials\answers\10632220\data\00.xml looks ok
found |ICOSTx|
** Bingo: Wrong number of arguments or invalid property assignment
<ICOS_ORDER_TX><HEADER>
<ID>49909171</ID>
<EMP>P9004952</EMP>
<STARTDT>10/04/2012 14:23:04</STARTDT>
<TOTAL>5849.59</TOTAL>
<CNP>1</CNP>
</HEADER>
</ICOS_ORDER_TX>