Reputation: 489
I am trying to create files based on the data provided in excel using vbscript/QTP. The problem I have is with negative testcases having special characters. I want to write special characters as node text but they are getting auto converted to escape characters.
Text to be written : address line one is<>"'& equal to 3 Actual Text after saving the file: address line one is<>"'& equal to 3
Is there any way to tell vbscript/XMLDOM not to convert these.
Code I am using is simple one.
Set NodeList = uxtXMLDoc.documentElement.selectSingleNode(strNodePath)
If Not(NodeList is Nothing) Then
NodeList.childNodes(0).nodeValue = "address line one is<>"'& equal to 3"
End If
Upvotes: 1
Views: 1630
Reputation: 489
With the use of @Kira 's solution and solutions posted at the below link I was able to create my solution. The issue is that XML replaces linearly from start to end.
Hence first ampersand in ("<") will be replaced as ("&lt") instead of (<).
You have to proactively replace the characters before XML replaces them.
strReplaceText = Replace(strtext, "<", chr(60)) //Sample... Repeat for all the chars
NodeList.childNodes(0).nodeValue = strReplaceText
objXML.Save(destination)
For more info, visit this thread. vbscript create-convert xml with special characters
Upvotes: 0
Reputation: 10360
Use the following line inside the 'If' condition:
NodeList.childNodes(0).nodeValue = "address line one is"&Chr(60)&Chr(62)&Chr(34)&chr(39)&"& equal to 3"
Here,
chr(60) means <
chr(62) means >
chr(34) means "
chr(39) means '
Upvotes: 2