Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
 
TitleEncode and decode special HTML characters by using XML documents
DescriptionThis example shows how to encode and decode special HTML characters by using XML documents in Visual Basic 6. It
KeywordsHTML, code, encode, XML, DomDocument
CategoriesInternet, 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 &lt;.

 
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 &lt; 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
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated