I have absolutly no idea when it comes to VBScript so I was quite happy when I frankensteined two simple code snippets found online to insert the entire contents of a text file into a XML document.
All works well except my <
have changed to <
and my <
has changed to >
.
How can I overcome this?
My code:
Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("C:\test.txt", ForReading)
strText = objTextFile.ReadAll
objTextFile.Close
Set xmlDoc = CreateObject("Microsoft.XMLDOM")
xmlDoc.Async = "False"
xmlDoc.Load("C:\Audits.xml")
Set colNodes = xmlDoc.SelectNodes("/TOOLS")
For Each objNode In colNodes
objNode.text = (strText)
Next
xmlDoc.Save "C:\Audits.xml"
You don't "overcome" this.
<
and>
characters must be encoded, otherwise there'd be issues with parsing the XML tags (which are demarcated by angular brackets, i.e.<
and>
characters).A CDATA section allows < and >:
(Docs)
Code:
output: