0

I am new to XML data and VBScript - Resources Ive found have not worked for me. I am trying to get the value from the XML when there is a match for a country.

E.g. Search for UNITED KINGDOM and retrieve the value.

Can someone please help me solve this in VBScript? Thanks!!

My XML file is below...

<root>

<!-- 
************************
::List:: COUNTRY::
************************
 -->

<COUNTRY>
    <Name>UNIED KINGDOM</Name>
    <Region>E</Region>
    <SETTING>I want this value</SETTING>
    <COUNTRYCODE>GB</COUNTRYCODE>
</COUNTRY>

This is the code I tried from TechNet

Set xmlDoc = CreateObject( "Microsoft.XMLDOM" )
xmlDoc.Async = "False"
xmlDoc.Load( "Data.xml")

strQuery = "Root[COUNTRY = 'UNITED KINGDOM']/SETTING"
Set colNodes = xmlDoc.selectNodes( strQuery )
For Each objNode in colNodes
Msgbox objNode.text
Next
user3099768
  • 3
  • 1
  • 4
  • If you want help, you need to show your code. What resources have you found? What did you try? What errors did you receive? What do you make of them? – Tomalak Dec 13 '13 at 14:41
  • Maybe this would help: http://stackoverflow.com/questions/9723903/navigating-xml-nodes-in-vbscript-for-a-dummy – drew_w Dec 13 '13 at 14:49
  • the XPath query is wrong. `/root/COUNTRY[Name = 'UNITED KINGDOM']/SETTING` (XPath is case sensitive) – Tomalak Dec 13 '13 at 15:27
  • In addition to @Tomalak, there is a typo in data.xml UNI `T` ED KINGDOM. Keep this also in mind. – Kul-Tigin Dec 14 '13 at 12:24

1 Answers1

0

I hope this helps. This is the VB Script.

 <script type="text/vbscript" >
 'Msg box Call 

 MsgBox XML_Read_Value_byTag ("Path of File", "Name") 'Name is the node,can be Region too

 ' this is the Function call     

Function XML_Read_Value_byTag(XMLFileName, XMLTag)
Set oXMLFile = CreateObject("Msxml2.DOMDocument") 
    oXMLFile.Load(XMLFileName)
Set oXMLFileVariale = oXMLFile.getElementsByTagName(XMLTag)
    XML_Read_Value_byTag = oXMLFileVariale.Item(0).Text
 End Function

</script>
user2526236
  • 1,538
  • 2
  • 15
  • 29