Title | Encode and decode special HTML characters by using XML documents |
Description | This example shows how to encode and decode special HTML characters by using XML documents in Visual Basic 6. It |
Keywords | HTML, code, encode, XML, DomDocument |
Categories | Internet, Strings |
|
|
Thanks to James Hansen.
Function HTMLToCharCodes loads HTML text into a DOM Document. It then returns the text value of the document. This value converts special characters such as < into their HTML codes <.
|
|
Public Function HTMLToCharCodes(ByVal iString As String) As _
String
With New MSXML2.DOMDocument30
.loadXML "<p>" & iString & "</p>"
HTMLToCharCodes = _
.selectSingleNode("p").nodeTypedValue
End With
End Function
|
|
Function CharCodesToHTML loads an HTML string into a DOM Document node and then reads out its XML text. That converts special character codes such as < into their character values <.
|
|
Public Function CharCodesToHTML(ByVal iString As String) As _
String
Dim iXml As New MSXML2.DOMDocument30
With iXml.createTextNode(iString)
CharCodesToHTML = .xml
End With
End Function
|
|
|
|