The ZAZ Blog: When all you have is a chicken and a rocket launcher, make some really badass scrambled eggs.

Converting HTML Entities [Updated]
« Previous Entry | Home | Next Entry »

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 &#156; 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.

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.


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.