VBScript中是否有可以在经典ASP页面中使用的encodeURIComponent或Uri.EscapeDataString?
我需要这个函数来生成jQuery可解析的XML。
Server.HTMLEncode无法完成任务。
答案 0 :(得分:1)
如果您愿意,您可以自己逃避角色,根据此链接,只有五个:What characters do I need to escape in XML documents?
因此,这样的事情应该有效:
//usage
EncodedXML = XMLEncode(MyDecodedXML)
//function
Function XMLEncode(str)
XMLEncode = str
If varType(XMLEncode) < 2 Exit Function
XMLEncode = Replace(XMLEncode,Chr(34),""")
XMLEncode = Replace(XMLEncode,"'","'")
XMLEncode = Replace(XMLEncode,"<","<")
XMLEncode = Replace(XMLEncode,">",">")
XMLEncode = Replace(XMLEncode,"&","&")
End Function
否则,通常使用VBS中的MSXML2.DOMDocument
对象完成此操作。文档可用here。一个简单的例子就是......
sFilePath = "D:\someplace\somefile.xml"
sXPath = "/SomeName/Someproperty"
Set oXMLDoc = CreateObject("MSXML2.DOMDocument")
oXMLDoc.SetProperty "SelectionLanguage", "XPath"
oXMLDoc.Async = False
oXMLDoc.Load sFilePath
If (oXMLDoc.parseError.errorCode <> 0) Then
Set oErr = oXMLDoc.ParseError
WScript.Echo "Could not load file " & sFilePath _
& " , error: " & oErr.Reason
WScript.Quit
End If
Set objNames = oXMLDoc.DocumentElement.SelectNodes(sXPath)
For Each obj in objNames
with obj
wsh.echo .nodeName, .getAttribute("name")
end with
Next