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
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? Commented Dec 13, 2013 at 14:41
  • Maybe this would help: stackoverflow.com/questions/9723903/… Commented Dec 13, 2013 at 14:49
  • the XPath query is wrong. /root/COUNTRY[Name = 'UNITED KINGDOM']/SETTING (XPath is case sensitive) Commented Dec 13, 2013 at 15:27
  • In addition to @Tomalak, there is a typo in data.xml UNI T ED KINGDOM. Keep this also in mind. Commented Dec 14, 2013 at 12:24

1 Answer 1

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>
Sign up to request clarification or add additional context in comments.

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.