0

I have following xml file & I would like to extract variable name & its value. can you please help me out to get this done. My xml format is

<?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>

and I am expecting the output like e.g. executablePath="D:\MyExe.exe"

Thanks in advance

2
  • the first 2 points of this answer should get you started Commented Apr 4, 2012 at 7:59
  • @Nathan Rice I tried below code and able to get the required value and variables but stuck to retreive connectionstring variable and its value Set xmlDoc = CreateObject("Microsoft.XMLDOM") xmlDoc.async = "False" xmlDoc.Load ("C:\test\myxml.xml") strQuery = "/configuration/applicationSettings/MyApps.Properties.Settings/*" Set colItem = xmlDoc.SelectNodes(strQuery) For Each objItem In colItem If objItem.Attributes.Length > 0 Then MsgBox objItem.Attributes(0).Text & ": " & objItem.Text End If Next Commented Apr 5, 2012 at 5:20

2 Answers 2

1

You can try the following as well. Leverages 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
Sign up to request clarification or add additional context in comments.

Comments

0

Finally I found my answer, can someone suggest better option if any? below is script that wrok for me

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.