Posts tagged ‘html’
Convert HTML entities from XML in JavaScript
Sometimes you get passed a string from XML and it can contain HTML entities like the following
&
<
>
"
©
®
«
»
'
If you write the string with JavaScript then you get something like didn't instead of didn’t
I’ve searched around for a function that could handle this but could not find one, so I wrote my own. I thought I’d share it with the world!
The following will convert & to &, convert ' to ‘ etc.
Following is the code, if you need help implementing it, I’m more than happy to explain how you install and run this function in return for a text link on your website, now that’s cheap as, considering I normally charge $140 an hour 😉
String.prototype.trim = function () { return this.split( /\s/ ).join( " " ); } String.prototype.convertHTMLEntity = function () { var myString = this; myString = myString.replace( /\&/g, '&' ); myString = myString.replace( /\</g, '<' ); myString = myString.replace( /\"/g, '"' ); myString = myString.replace( /\©/g, '©' ); myString = myString.replace( /\®/g, '®' ); myString = myString.replace( /\«/g, '«' ); myString = myString.replace( /\&raqou;/g, '»' ); myString = myString.replace( /\'/g, "'" ); return myString; }
ColdFusion HTML Validation Library
ColdFusion library to perform HTML Validation through http://validator.w3.org/ it allows you to programmatically query http://validator.w3.org/ for invalid markup (HTML, XHTML, …).
Continue Reading January 2, 2008 at 1:12 am Taco Fleur Leave a comment
Recent comments