vbs test

'-----------------------------------
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")

转载于:https://www.cnblogs.com/developer-ios/p/6212514.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值