在VB6中使用encodeURIComponent或Escape [英] encodeURIComponent or Escape in VB6
问题描述
我需要这个函数来生成jQuery可解析的XML。 p>
Server.HTMLEncode没有完成任务。
你可以根据这个链接,只要你自己逃避这些角色就只有五个:我需要在XML文档中转义哪些字符?
因此,这样的东西应该可以工作:
//用法
EncodedXML = XMLEncode(MyDecodedXML)
//功能
函数XMLEncode(str)
XMLEncode = str
如果varType(XMLEncode)< 2退出函数
XMLEncode =替换(XMLEncode,Chr(34),&)
XMLEncode =替换(XMLEncode,',&)
XMLEncode = Replace(XMLEncode,,&)
XMLEncode =替换(XMLEncode,>,& gt)
XMLEncode = &,& amp;)
结束函数
否则,通常使用VBS中的 MSXML2.DOMDocument
对象完成。文档可以 here 。一个简单的例子就是...
sFilePath =D:\someplace\somefile.xml
sXPath =/ SomeName / Someproperty
设置oXMLDoc = CreateObject(MSXML2.DOMDocument)
oXMLDoc.SetPropertySelectionLanguage,XPath
oXMLDoc.Async = False
oXMLDoc.Load sFilePath
If(oXMLDoc.parseError.errorCode<> 0)然后
设置oErr = oXMLDoc.ParseError
WScript.Echo无法加载文件& sFilePath _
& ,错误:& oErr.Reason
WScript.Quit
End If
设置objNames = oXMLDoc.DocumentElement.SelectNodes(sXPath)
对于objNames中的每个obj
与obj
wsh.echo .nodeName,.getAttribute(name)
结束
下一个
Is there a encodeURIComponent or Uri.EscapeDataString in VBScript that can be used in an classic ASP page?
I need this function to generate jQuery parseable XML.
Server.HTMLEncode does not do a complete job.
You can just escape the characters yourself if you would like, according to this link, there are only five: What characters do I need to escape in XML documents?
Therefore, something like this should work:
//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
Otherwise, this is generally done using the MSXML2.DOMDocument
object in VBS. Documentation is available here. A simple example of its use is ...
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
这篇关于在VB6中使用encodeURIComponent或Escape的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!