Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
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.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - best way to get xml value

Reply
 
Old 06-09-2009   #1 (permalink)
Big D


 
 

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 SpecsSystem Spec
Old 06-10-2009   #2 (permalink)
Tim Williams


 
 

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 SpecsSystem Spec
Old 06-10-2009   #3 (permalink)
Joe Fawcett


 
 

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 SpecsSystem Spec
Old 06-10-2009   #4 (permalink)
Big D


 
 

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 SpecsSystem Spec
Old 06-24-2009   #5 (permalink)
Joe Fawcett


 
 

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 SpecsSystem Spec
Reply

Thread Tools



Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46