ここからの情報に基づく:
.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>