Today I purchased RegexBuddy, a tool for creating and testing regular expressions. Regular expressions are strings that describe or match a set of strings, according to certain syntax rules. In other words, a regular expression is a complex syntax for searching through text. It is very handy for search and replace and many mundane programming tasks that require text manipulation. I bought RegexBuddy because I am doing a lot of work with XSL, stylesheets for XML. Unfortunately, there are many occasions when XSL is not sophisticated enough to pull data from a RSS or XML feed. It is often necessary to do additional string parsing using JavaScript. One of the more useful features of JavaScript is its support for regular expressions. RegexBuddy is great for creating complicated regular expressions and testing them against sample data. It will even generate some of the JavaScript code you need to use regular expressions. RegexBuddy is only $29.95 so I found it affordable.
I need to write some JavaScript functions for my XSL stylesheet I’m developing for the YouTube user RSS feed. This XML feed is using RSS 2.0 with the xmlns:media extension. The description tag has been causing me a lot of grief because it breaks the design principles of XML. The description tag actually contains 5 pieces of information; the video thumbnail, the video description, the author, the keywords or tags, and the date added. All of this information is provided as HTML within a <
!
[CDATA[...]]
>
. CDATA sections instruct the XML processor that the content included in a section is not markup and should not be parsed. This makes it very difficult to extract the video description.
So far I have written the JavaScript function to strip out the newlines in the HTML, because regular expressions don’t work well on multiline text, and the function to trim the description. I’ve also come up with a good regular expression to find the text contained within the first paragraph HTML tags <
p>
<
/p>
which surround the video description. However, I am still having problems with the XSL which needs to pass the description element to my JavaScript function and then return a string I'll use within a title tag attribute as a tooltip. When you mouse over the video title I want to display the video description.