当前位置: 移动技术网 > IT编程>脚本编程>VBScript > vbscript 读取xml格式的配置文件

vbscript 读取xml格式的配置文件

2017年12月08日  | 移动技术网IT编程  | 我要评论

笑笑离世后罗尔首次发声,难得爱浓,美容小常识大全

复制代码 代码如下:

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

配置文件格式:
复制代码 代码如下:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<!--メッセージ定義
-->
<messagedefine>
<info.001 value="処理開始。"/>
<info.002 value="処理終了。"/>
<info.003 value="処理異常終了。"/>
<info.004 value="処理中止。"/>
</messagedefine>
<!-- その他配置
-->
<othersection>
<host value="192.168.0.241"/>
<user value="root"/>
</othersection>
<windowslogtoolconfig>
<host value="192.168.0.188"/>
<port value="3306"/>
</windowslogtoolconfig>
</configuration>

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网