XML VBScript Assistance?

I am trying to extract data from a file I have in an address application.

The format of the file is:

<?xml version="1.0" encoding="iso-8859-1"?>
<addressSetting value="Corporate">
Corp Way</streetAddress>
<addressSetting value="Remote1">
Remote Way</streetAddress>

I am trying to use VBScript to Extract each value so I can import it into system for badging (not relevant).

I have tried different XML code snippets from this site and many others but can't get the script to dump out what I need.

I would like to set each value (address, State, Zip) as a unique varible (i.e. strState=oNode.SelectSingleNode("stateOrProvince").text but nothing seems to work.

Any assistance is appreciated.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You could do something a bit like this.

Const ForReading = 1

Set fso = CreateObject("Scripting.FileSystemObject")

Set XMLReader = fso.OpenTextFile("C:\Temp\Address.xml", ForReading)
Do While Not XMLReader.AtEndOfStream
ReadXML = XMLReader.ReadLine

If InStr(1,ReadXML,"city")>0 Then
	CITY = Replace(ReadXML,"<city>",vbNullString)
	CITY = Replace(CITY,"</city>",vbNullString)
End If

If InStr(1,ReadXML,"stateOrProvince")>0 Then
	State = Replace(ReadXML,"<stateOrProvince>",vbNullString)
	State = Replace(State,"</stateOrProvince>",vbNullString)
End If

If InStr(1,ReadXML,"country")>0 Then
	country = Replace(ReadXML,"<country>",vbNullString)
	country = Replace(country,"</country>",vbNullString)
End If

If InStr(1,ReadXML,"streetAddress")>0 Then
	Street = Replace(ReadXML,"<streetAddress>",vbNullString)
	Street = Replace(Street,"</streetAddress>",vbNullString)
End If

If InStr(1,ReadXML,"zipOrPostalCode")>0 Then
	Postcode = Replace(ReadXML,"<zipOrPostalCode>",vbNullString)
	Postcode = Replace(Postcode,"</zipOrPostalCode>",vbNullString)
End If


WScript.Echo Street & vbCrLf & City & vbCrLf & State & vbCrLf & Postcode & vbCrLf & Country

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Hi, this will list the node values in the XML, but it's not clear what you want to do with each value....


Const NODE_TEXT = 3
Set objXML = CreateObject("Microsoft.XMLDOM")
Set objFSO = CreateObject("Scripting.FileSystemObject")
strXMLFile = Replace(WScript.ScriptFullName, WScript.ScriptName, "") & "test.xml"
If objXML.load(strXMLFile) Then
	DisplayNode objXML.childNodes, 0
	MsgBox "Unable to load " & strXMLFile
End If

MsgBox "Finished."

Sub DisplayNode(ByRef Nodes, ByVal Indent)
	Dim xNode
	Indent = Indent + 2

	For Each xNode In Nodes
		If xNode.nodeType = NODE_TEXT Then
			WScript.Echo Space(Indent) & xNode.parentNode.nodeName & ": " & xNode.nodeValue
		End If

		If xNode.hasChildNodes Then
			DisplayNode xNode.childNodes, Indent
		End If
End Sub

Open in new window

Glen KnightCommented:
This question has been classified as abandoned and is being closed as part of the Cleanup Program. See my comment at the end of the question for more details.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.