0
XMLファイル内のすべての要素を繰り返し処理し、テキストファイルを使用して要素に値を割り当てます。すべてのXML要素をループし、テキストファイルの入力に基づいてXMLファイルを追加します。
project_template.xml
:
<project baseDir="" outputDir="">
<rule inherit="" preset="" pattern="" />
</project>
test.txt
:
baseDir="test1" outputDir="test2" inherit="test3" preset="test4" pattern="true"
Project.vbs
:
Option Explicit
Dim arrFileLines(), final(45)
Dim i, objFSO, objFile, l, index, finalString
i = 0
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Users\1021752\Desktop\project\test.txt", 1)
Do Until objFile.AtEndOfStream
ReDim Preserve arrFileLines(i)
arrFileLines(i) = objFile.ReadLine
i = i + 1
Loop
objFile.Close
Const NODE_ELEMENT = 1
Const CONFUSER_NS = "http://confuser.codeplex.com"
Dim doc, moduleElem, args, arg
Set args = WScript.Arguments
Set doc = CreateObject("Msxml2.DOMDocument")
doc.Async = False
doc.Load "project_template.xml"
If doc.ParseError.ErrorCode Then
WScript.Echo doc.ParseError
WScript.Quit 1
End If
For l = LBound(arrFileLines) To UBound(arrFileLines) Step 1
index = InStr(1, arrFileLines(l), "=")
final(l) = Right(arrFileLines(l), Len(arrFileLines(l)) - index)
Next
doc.DocumentElement.SetAttribute "baseDir", final(0) 'here I am manually assigning the value to the "baseDir"
doc.DocumentElement.SetAttribute "outputDir", final(1)
doc.DocumentElement.SetAttribute "inherit", final(2)
doc.DocumentElement.SetAttribute "preset", final(3)
doc.DocumentElement.SetAttribute "pattern", final(4)
doc.Save "project.xml"
所望の出力:
<project baseDir="test1" outputDir="test2" >
<rule inherit="test3" preset="test4" pattern="true" />
</project>
XMLファイル内のすべての要素を反復処理して名前を返すようにします。
Iはnode.Attributes node.SetAttributeのATTRの各ATTRについて Iは、IF文 'サブUpdateAttributes(ノード値)を除去し、ビットのコードを変更し、値(ATTR) 次に .ChildNodes 更新eAttributes child、values 次 End Sub'このメソッドを実装して実行すると、型不一致エラー800A000Dがスローされています。あなたは解決策が見つからなかったので解決するのを助けてくれますか? –
'attr'だけでなく、' attr.Name'を使う必要があります。更新された回答をご覧ください。 –