Convert sql_latin1_general_cp1_ci_as string to utf8 using VBS
i have to write a script that converts a string from a MSSQL Server database in sql_latin1_general_cp1_ci_as into a value in an XML file, which is in UTF8 encoding. Does anyone have an idea how t开发者_Python百科o do in in VBS?
Thanks!
you might need to add a bit more context to your question, but a first answer would be to query the database using ADODB, load your XML into MSXML2, use XPath to select the node in which you want to add your result then insert the string as the node text.
''#open the data
dim ado: set ado = CreateObject("ADODB.Connection")
ado.ConnectionString = "..."
ado.open
dim rs: set rs = ado.Execute("SELECT TOP 1 your_string FROM your_data_table")
''#open the XML
dim xmldoc: set xmldoc = CreateObject("MSXML2.DomDocument")
xmldoc.async = false
xmldoc.setProperty "SelectionLanguage", "XPath"
''# you might also need setProperty "SelectionNamespaces", "xmlns=..." depending on your XML
xmldoc.load "path\to\your\XML"
''# store the string in the XML and save
xmldoc.selectSingleNode("//xpath/to/your/target/node").text = rs.fields["your_string"].value
xmldoc.save "path\to\your\output\xml"
rs.close
ado.close
If you're already at this point, let me know if you are having any specific problems
精彩评论