' VBScript File
Dim inPath
Dim outPath

Dim xml
Dim doc
Dim fso
Dim files

inPath = "C:\files\sample\source\"
outPath = "C:\files\sample\dest\"

Set fso = createobject("Scripting.FileSystemObject")
Set xml = createobject("Microsoft.XMLDOM")
xml.async = false
xml.validateOnParse = false
xml.resolveExternals = false
xml.setProperty "SelectionLanguage", "XPath"
xml.setProperty "ServerHTTPRequest", True

Set files = fso.GetFolder (inPath).Files
for each file in files

    if (lcase(right(file, 4)) = ".xml") then
        wscript.echo file
        xml.load("" & file & "")
        
            Dim text
            text = htmlDecode(xml.selectSingleNode ("/slot/payload/object/@content").text)
            
            Set outFile = fso.CreateTextFile(replace(file, inPath, outPath))
            outFile.writeline("<?xml version='1.0' encoding='utf-8' ?>")
            outFile.write(htmlDecode(text))
            outFile.close
            
        
        
    end if

next

function htmlDecode (htmlString)

	Dim tmp, i
	tmp = htmlString
	tmp = Replace( tmp, "&quot;", chr(34) )
	tmp = Replace( tmp, "&lt;"  , chr(60) )
	tmp = Replace( tmp, "&gt;"  , chr(62) )
	tmp = Replace( tmp, "&amp;" , chr(38) )
	tmp = Replace( tmp, "&nbsp;", chr(32) )
	For i = 1 to 255
		tmp = Replace( tmp, "&#" & i & ";", chr( i ) )
	Next
	htmlDecode = tmp

end function
