Friday, August 24, 2007

Transforming XML into HTML when the XML has HTML in its contents

So I’m creating this Mac Noland website right. For some reason I would like to create a small widget which simply displays the most current thread of the Mac’s Thoughts blog (i.e. this blog you’re reading now). I’m not sure how much value it adds, but it just seems like a cool experiment, so I thought we’d give it a try.

Anyway, it took me some time to get the code figured out. To be honest, I didn’t really figure any code out – which is typical. I used this cordial Frenchman’s idea and changed it slightly for my website. I’m not 100% sure if this is the right way to do things, but with a few modifications the approach works for me.

The blog was being pulled in, but unfortunately I was getting < B / > in my content and the browser was not rendering it (similar to what you're seeing now). Reason being is the < B / > in the XML was being escaped. So I spent the next few hours tracking down the fix, which as usual, was pretty simple. All I had to do is put the attribute disable-output-escaping="yes" on my value-of select statement. The W3Schools website does a fair job explaining this.

While my website is a ways off from being released, at least my blog will showing up on the front page once we get started. I’m sure the average engineer already knows this stuff, but if you’re below average like me, I hope this helps you out.

No comments: