Converting HTML Entities [Updated]
« Previous Entry | Home | Next Entry »
Written by Thom McGrath on Saturday, September 22, 2007 at 6:20 PM (-05:00)
Categories: Announcements (13), REALSyndication (4), REALbasic (14)
Tags: HTML (1)
Download HTMLEntities Module
Size: 8.8 KB
I've made another mini-release. This is simply a REALbasic module which allows quick conversion back and forth between HTML entities, and their actual character.
If you are not sure what I mean, the problem generally arises in XML. For example, in an XML element, characters such as < and > are can mess up the parser. So there are two options: wrap the content in a CDATA section, or convert the content to "XML-Safe" - which this module does.
It also converts back to the original characters, and converts code points as well, but only in UTF-8. These are bits of content that look like œ which the gets converted to a character using REALbasic's Chr function. Adding support for customizable encodings should not be difficult.
There are two methods to think about. EscapeHTML and UnescapeHTML. They can be used either as methods of the module, or methods of the string. For example:
MyString = EditField1.Text.EscapeHTML
Or
MyString = HTMLEntities.EscapeHTML(EditField1.Text)
Either method is fine.
[Update]
The original module had a case-sensitivity mistake. This has been corrected, but it's now a module and a class, rather than just a module. The setup is still quite fast, and self-initializing.
License: Creative Commons (details) | Digg | E-Mail Thom McGrath
View More Entries From The Same: Day | Month | Year
Comments
Comments are being accepted below.
Pings
This entry is accepting pings.
Disclaimer: I am currently an employee of REAL Software. My comments and opinions are mine alone and do not represent those of my employer. My posts are not official REAL Software communications, and may contain information that is incorrect or misleading.
Leave a comment
We utilize unique methods to ensure your email address stays private while remaining useful.
Depending on the authentication scheme used, some or all of the personal data entered below will be ignored in favor of the data stored with your account.