2012-04-04 14 views
0

次のxmlファイルがあります&変数名&を抽出したいと思います。これを行うために私を助けてもらえますか? 私のxml形式はvbscriptを使用してxmlファイルから変数名とその値を抽出する方法

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
    <configSections> 
     <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" > 
      <section name="MyApps.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> 
     </sectionGroup> 
    </configSections> 
    <connectionStrings> 
     <add name="MyApps.Properties.Settings.dbConnString" connectionString="Data Source=MSTEST01\TQA;Initial Catalog=TQA;Persist Security Info=True;User ID=UserID;Password=Pwd" 
      providerName="System.Data.SqlClient" /> 
    </connectionStrings> 
    <applicationSettings> 
     <MyApps.Properties.Settings> 
      <setting name="BasePath" serializeAs="String"> 
       <value>\\Results</value> 
      </setting> 
      <setting name="cPath" serializeAs="String"> 
       <value>C:\Controller</value> 
      </setting> 
      <setting name="ePath" serializeAs="String"> 
       <value>C:\Debug\E.exe</value> 
      </setting> 
      <setting name="fPath" serializeAs="String"> 
       <value>C:\Framework</value> 
      </setting> 
      <setting name="engineId" serializeAs="String"> 
       <value>1</value> 
      </setting> 
      <setting name="wPath" serializeAs="String"> 
       <value>C:\S5</value> 
      </setting> 
     </MyApps.Properties.Settings> 
    </applicationSettings> 
</configuration> 

であり、私は、例えばのような出力を期待していますexecutablePath = "D:\ MyExe.exe" 事前

+0

[この回答](http://stackoverflow.com/a/2181953/69820)の最初の2点は、あなたが –

+0

@Nathanライスを始める必要がある私は、コードの下にしようと、必要な値を得ることができ、および( "Microsoft.XMLDOM") xmlDoc.async = "False" xmlDoc.Load( "C:\ test \ myxml.xml") strQuery = "接続変数の値を取得しようとしましたが、 /configuration/applicationSettings/MyApps.Properties.Settings/* " set colItem = xmlDoc.SelectNodes(strQuery) 各objItemに対してcolItem内 if objItem.Attributes.Length> 0 Then MsgBox objItem.Attributes(0).Text& ":"&objItem.Text 終了の場合 次へ – Shree

答えて

0

おかげで最後に私がもしあれば、誰かがより良い選択肢を提案することができ、私の答えを見つけましたか?以下は私のためのスクリプトです

Set xmlDoc = CreateObject("Microsoft.XMLDOM") 

xmlDoc.async = "False" 
xmlDoc.Load ("C:\STEPRunRequest\STEPRunner.exe.config") 
strQuery = "/configuration/applicationSettings/Eunner.Properties.Settings/*" 

Set colItem = xmlDoc.SelectNodes(strQuery) 
Set xmlElement = xmlDoc.DocumentElement.SelectSingleNode("/configuration/configSections[@connectionStrings]") '='" <SomeValue> & "' 
Set queryNode = xmlDoc.SelectSingleNode(".//node()[@connectionString]") 
MsgBox queryNode.Attributes(1).Text 

For Each objItem In colItem 
If objItem.Attributes.Length > 0 Then 
    MsgBox objItem.Attributes(0).Text & ": " & objItem.Text 

End If 
Next 
1

あなたも次のように試すことができます。 getAttributeを利用する - Cscript vbs。

Set objXML2 = CreateObject("Microsoft.XMLDOM") 
objXML2.async = "false" 
strdir="c:\config.xml" 
If (Not objXML2.load(strdir)) Then 
    wscript.echo "Unable to load file '" & strdir & "'. " 
    WScript.Quit(1) 
End If 

Set colNodes = objXML2.selectNodes ("/configuration/applicationSettings/Eunner.Properties.Settings") 
For Each objNode in colNodes 
    wscript.echo objnode.getAttribute("name")& " : " & objNode.text 
Next 
関連する問題