'-----------------------------------
Class clsGetProfile
Private rootDoc
Public Sub setProfile(strFileName)
Set data_xml = CreateObject("Microsoft.XMLDOM")
data_xml.async = False
data_xml.load(strFileName)
Set rootDoc = data_xml.documentElement
Dim objDict
Set objDict = WSH.CreateObject("Scripting.Dictionary")
'objDict.Add "aaa","hehe"
'WSH.Echo(objDict.Item("aaa"))
Set VarsNode=rootDoc.selectSingleNode("var")
Set VarNodes=VarsNode.childNodes
s=VarNodes.length
'---start set vars
for i = 0 to s-1
Set VarNode= VarNodes(i)
key = VarNode.getAttribute("name")
value= VarNode.Text
Dim keys,items
keys=objDict.Keys
items=objDict.Items
for j=0 to objDict.Count-1
value=Replace(value,"${"&keys(j)&"}",items(j))
next
objDict.Add key,value
'resetStr=Replace("x${qqq}nnn","${"&key&"}",value)
next
'--- end set vars
'msgbox objDict.item("target")
'filePath=objDict.item("configFile")
'fileText=Replace(fileText,"${HYBRIS_LOG_DIR}","xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
'msgbox "==="&fileText
'saveText "d:/AAAAS.txt",fileText
filePath=objDict.item("source")
filePath=Trim(filePath)
filePathTarget=objDict.item("target")
filePathTarget=Trim(filePathTarget)
textContent=getText(filePath)
Set messageNode=rootDoc.selectSingleNode("message") ' //getElementsByTagname("key")
Set KeyNodes=messageNode.childNodes
s=KeyNodes.length
keys=objDict.Keys
items=objDict.Items
for i = 0 to s-1
Set KeyNode= KeyNodes(i)
key = KeyNode.getAttribute("name")
value= KeyNode.Text
for j=0 to objDict.Count-1
value=Replace(value,"${"&keys(j)&"}",items(j))
next
textContent=Replace(textContent,"${"&key&"}",value)
'msgbox value
'replace=bbb
'resetStr=Replace("x${xxxx}nnn","${"&key&"}",value)
next
saveText filePathTarget,textContent
If data_xml.parseError.errorCode <> 0 Then
MsgBox "XML文件格式不对,原因是:" & Chr(13) & data_xml.parseError.reason
End If
End Sub
' 读取文件
public Function getText(filePath)
set fso=createobject("scripting.filesystemobject")
set file=fso.opentextfile(filePath)
strCopy = file.readall
file.close
getText=strCopy
End Function
public Function SaveText(filePath,content)
set fso=createobject("scripting.filesystemobject")
Set f = fso.CreateTextFile(filePath,True)
f.write(content)
f.close
End Function
Public Function getItem(massage, itemName)
Set xxx=rootDoc.selectSingleNode(strSectionName)
MsgBox itemName
getItem=xxx.selectSingleNode("Info.001").getAttribute("value")
End Function
End Class
Dim config : Set config = New clsGetProfile
Call config.setProfile("Config.xml")
'WScript.Echo config.getItem("message", "INFO.001")
'WScript.Echo config.getItem("MessageDefine", "INFO.003")
'WScript.Echo config.getItem("MessageDefine", "ERROR.009")
'WScript.Echo config.getItem("MessageDefine", "ERROR.012")