![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | best way to get xml value Wha t's the best way to get the TEST2 value FROM PROD from xml file? Below is sample xml file. I stripped the file down for simplicity. '*************************XML LAYOUT********************** <Parameters> <Environment Id="PROD"> <variable name="MyPRODTest1" value="PRODTEST1"/> <variable name="MyPRODTest2" value="PRODTEST2"/> </Environment> <Environment Id="QA"> <variable name="MyQATest1" value="QATEST1"/> <variable name="MyQATest2" value="QATEST2"/> </Environment> </Parameters> ************************************************************ I wrote a function that loads up the xml file to return the data. I feel like if I know the environment id and value I should be able to just select it. Currently I have two for loops to get the value I need. Set xml = GetParametersXML() 'load up the xml document function. data store in xml variable. Env="PROD" Set Environments = xml.getElementsByTagName("Environment") For Each Environment In Environments sEnvironmentId=Environment.Attributes.getNamedItem("Id").value If sEnvironmentId = Env Then Set variables = Environment.getElementsByTagName("variable") Next End If Next |
My System Specs![]() |
| | #2 (permalink) |
| | Re: best way to get xml value You should be able to use XPATH for this. Here's a sample tutorial : http://www.w3schools.com/XPath/default.asp (can't vouch for its quality) Plenty other examples on Google Tim "Big D" <BigDaddy@xxxxxx> wrote in message news:eRsbqdW6JHA.5180@xxxxxx Quote: > Wha t's the best way to get the TEST2 value FROM PROD from xml file? Below > is sample xml file. I stripped the file down for simplicity. > > > > '*************************XML LAYOUT********************** > <Parameters> > <Environment Id="PROD"> > <variable name="MyPRODTest1" value="PRODTEST1"/> > <variable name="MyPRODTest2" value="PRODTEST2"/> > </Environment> > <Environment Id="QA"> > <variable name="MyQATest1" value="QATEST1"/> > <variable name="MyQATest2" value="QATEST2"/> > </Environment> > </Parameters> > ************************************************************ > > I wrote a function that loads up the xml file to return the data. I feel > like if I know the environment id and value I should be able to just > select it. Currently I have two for loops to get the value I need. > > Set xml = GetParametersXML() 'load up the xml document function. data > store in xml variable. > Env="PROD" > > > Set Environments = xml.getElementsByTagName("Environment") > > For Each Environment In Environments > sEnvironmentId=Environment.Attributes.getNamedItem("Id").value > If sEnvironmentId = Env Then > Set variables = Environment.getElementsByTagName("variable") > > Next > End If > Next > |
My System Specs![]() |
| | #3 (permalink) |
| | Re: best way to get xml value I'd use XPath, look at the selectSingleNode method. The XPath could be: /Parameters/Environment[@Id = 'PROD']/variable[@name = 'myPRODTest2']/@value -- Joe Fawcett (MVP - XML) http://joe.fawcett.name "Big D" <BigDaddy@xxxxxx> wrote in message news:eRsbqdW6JHA.5180@xxxxxx Quote: > Wha t's the best way to get the TEST2 value FROM PROD from xml file? Below > is sample xml file. I stripped the file down for simplicity. > > > > '*************************XML LAYOUT********************** > <Parameters> > <Environment Id="PROD"> > <variable name="MyPRODTest1" value="PRODTEST1"/> > <variable name="MyPRODTest2" value="PRODTEST2"/> > </Environment> > <Environment Id="QA"> > <variable name="MyQATest1" value="QATEST1"/> > <variable name="MyQATest2" value="QATEST2"/> > </Environment> > </Parameters> > ************************************************************ > > I wrote a function that loads up the xml file to return the data. I feel > like if I know the environment id and value I should be able to just > select it. Currently I have two for loops to get the value I need. > > Set xml = GetParametersXML() 'load up the xml document function. data > store in xml variable. > Env="PROD" > > > Set Environments = xml.getElementsByTagName("Environment") > > For Each Environment In Environments > sEnvironmentId=Environment.Attributes.getNamedItem("Id").value > If sEnvironmentId = Env Then > Set variables = Environment.getElementsByTagName("variable") > > Next > End If > Next > |
My System Specs![]() |
| | #4 (permalink) |
| | Re: best way to get xml value Running into an issue. Started creating function to get the value needed. Function GetEnvironmentId() Dim envxml,strEnvId Set envxml = GetEnvParametersXML(CONST_ENVPARAMETERS_XML_FILE) 'function loads up xml and stores in envxml Set strEnvId = envxml.DocumentElement.SelectSingleNode("//Parameters/Environment[@Id='PROD']/variable[@name =MyPRODTest2"]/@value") Wscript.Echo strEnvId.Text End Function 'getting error when I try to output the value. "Joe Fawcett" <joefawcett@xxxxxx> wrote in message news:eyMDtea6JHA.4632@xxxxxx Quote: > I'd use XPath, look at the selectSingleNode method. > The XPath could be: /Parameters/Environment[@Id = 'PROD']/variable[@name = > 'myPRODTest2']/@value > > -- > > Joe Fawcett (MVP - XML) > > http://joe.fawcett.name > > "Big D" <BigDaddy@xxxxxx> wrote in message > news:eRsbqdW6JHA.5180@xxxxxx Quote: >> Wha t's the best way to get the TEST2 value FROM PROD from xml file? >> Below is sample xml file. I stripped the file down for simplicity. >> >> >> >> '*************************XML LAYOUT********************** >> <Parameters> >> <Environment Id="PROD"> >> <variable name="MyPRODTest1" value="PRODTEST1"/> >> <variable name="MyPRODTest2" value="PRODTEST2"/> >> </Environment> >> <Environment Id="QA"> >> <variable name="MyQATest1" value="QATEST1"/> >> <variable name="MyQATest2" value="QATEST2"/> >> </Environment> >> </Parameters> >> ************************************************************ >> >> I wrote a function that loads up the xml file to return the data. I feel >> like if I know the environment id and value I should be able to just >> select it. Currently I have two for loops to get the value I need. >> >> Set xml = GetParametersXML() 'load up the xml document function. data >> store in xml variable. >> Env="PROD" >> >> >> Set Environments = xml.getElementsByTagName("Environment") >> >> For Each Environment In Environments >> sEnvironmentId=Environment.Attributes.getNamedItem("Id").value >> If sEnvironmentId = Env Then >> Set variables = Environment.getElementsByTagName("variable") >> >> Next >> End If >> Next >> > |
My System Specs![]() |
| | #5 (permalink) |
| | Re: best way to get xml value You need single quotes around the MyPRODTest2 literal as my first example showed. -- Joe Fawcett (MVP - XML) http://joe.fawcett.name "Big D" <BigDaddy@xxxxxx> wrote in message news:eceswxc6JHA.3860@xxxxxx Quote: > Running into an issue. > > > Started creating function to get the value needed. > > > Function GetEnvironmentId() > Dim envxml,strEnvId > Set envxml = GetEnvParametersXML(CONST_ENVPARAMETERS_XML_FILE) > 'function loads up xml and stores in envxml > > Set strEnvId = > envxml.DocumentElement.SelectSingleNode("//Parameters/Environment[@Id='PROD']/variable[@name > =MyPRODTest2"]/@value") > > Wscript.Echo strEnvId.Text > > End Function > > > 'getting error when I try to output the value. > > > > "Joe Fawcett" <joefawcett@xxxxxx> wrote in message > news:eyMDtea6JHA.4632@xxxxxx Quote: >> I'd use XPath, look at the selectSingleNode method. >> The XPath could be: /Parameters/Environment[@Id = 'PROD']/variable[@name >> = 'myPRODTest2']/@value >> >> -- >> >> Joe Fawcett (MVP - XML) >> >> http://joe.fawcett.name >> >> "Big D" <BigDaddy@xxxxxx> wrote in message >> news:eRsbqdW6JHA.5180@xxxxxx Quote: >>> Wha t's the best way to get the TEST2 value FROM PROD from xml file? >>> Below is sample xml file. I stripped the file down for simplicity. >>> >>> >>> >>> '*************************XML LAYOUT********************** >>> <Parameters> >>> <Environment Id="PROD"> >>> <variable name="MyPRODTest1" value="PRODTEST1"/> >>> <variable name="MyPRODTest2" value="PRODTEST2"/> >>> </Environment> >>> <Environment Id="QA"> >>> <variable name="MyQATest1" value="QATEST1"/> >>> <variable name="MyQATest2" value="QATEST2"/> >>> </Environment> >>> </Parameters> >>> ************************************************************ >>> >>> I wrote a function that loads up the xml file to return the data. I feel >>> like if I know the environment id and value I should be able to just >>> select it. Currently I have two for loops to get the value I need. >>> >>> Set xml = GetParametersXML() 'load up the xml document function. data >>> store in xml variable. >>> Env="PROD" >>> >>> >>> Set Environments = xml.getElementsByTagName("Environment") >>> >>> For Each Environment In Environments >>> sEnvironmentId=Environment.Attributes.getNamedItem("Id").value >>> If sEnvironmentId = Env Then >>> Set variables = Environment.getElementsByTagName("variable") >>> >>> Next >>> End If >>> Next >>> >> > |
My System Specs![]() |