这篇文章主要为大家展示了“vbscript如何读取xml格式的配置文件”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“vbscript如何读取xml格式的配置文件”这篇文章吧。
复制代码 代码如下:
Class clsGetProfile
' ルートドキュメント
Private rootDoc
' xmlファイル名とセクション名をセットする
' 引数: 「1」ファイル名 NOT NULL
' 戻り値:なし
Public Sub setProfile(strFileName)
Set data_xml = CreateObject("Microsoft.XMLDOM")
data_xml.async = False
data_xml.load(strFileName)
Set rootDoc = data_xml.documentElement
End Sub
' キーの対応する値を取得する
' 引数: 「1」キー名 NOT NULL
' 「2」セクション名 NOT NULL
' 戻り値:キーの対応する値
Public Function getItem(strSectionName, itemName)
Set sectionNode = rootDoc.selectSingleNode(strSectionName)
getItem = sectionNode.selectSingleNode(itemName).attributes(0).nodeValue
End Function
End Class
' 使用サンプル
' クラスインスタンスを生成する
'Dim config : Set config = New clsGetProfile
' 配置ファイル名とセクション名をセットする
'Call config.setProfile("Config.xml")
' きーの対応する値をゲットする
'WScript.Echo config.getItem("MessageDefine", "INFO.001")
'WScript.Echo config.getItem("MessageDefine", "INFO.003")
'WScript.Echo config.getItem("MessageDefine", "ERROR.009")
'WScript.Echo config.getItem("MessageDefine", "ERROR.012")
Class clsGetProfile
' ルートドキュメント
Private rootDoc
' xmlファイル名とセクション名をセットする
' 引数: 「1」ファイル名 NOT NULL
' 戻り値:なし
Public Sub setProfile(strFileName)
Set data_xml = CreateObject("Microsoft.XMLDOM")
data_xml.async = False
data_xml.load(strFileName)
Set rootDoc = data_xml.documentElement
End Sub
' キーの対応する値を取得する
' 引数: 「1」キー名 NOT NULL
' 「2」セクション名 NOT NULL
' 戻り値:キーの対応する値
Public Function getItem(strSectionName, itemName)
Set sectionNode = rootDoc.selectSingleNode(strSectionName)
getItem = sectionNode.selectSingleNode(itemName).attributes(0).nodeValue
End Function
End Class
' 使用サンプル
' クラスインスタンスを生成する
'Dim config : Set config = New clsGetProfile
' 配置ファイル名とセクション名をセットする
'Call config.setProfile("Config.xml")
' きーの対応する値をゲットする
'WScript.Echo config.getItem("MessageDefine", "INFO.001")
'WScript.Echo config.getItem("MessageDefine", "INFO.003")
'WScript.Echo config.getItem("MessageDefine", "ERROR.009")
'WScript.Echo config.getItem("MessageDefine", "ERROR.012")
配置文件格式:
复制代码 代码如下:
以上是“vbscript如何读取xml格式的配置文件”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注创新互联行业资讯频道!