The challenge of embedding XML into a WordPress MU blog entry

March 31st, 2008 by Dan York

Given that we work with XML, we naturally want to include XML inside of our blog posts. However, that turns out to be a bit of a major headache. Over on our Voxeo Developer’s Corner blog, you can see what we are trying to do with posts like this one. We want to include snippets of XML code, complete with angle brackets, etc.

Obviously this can be done through good, old “HTML character entity substitution. In order to get:

<prompt>

we simply enter it into WordPress MU as:

&lt;prompt&gt;

We can do that - and certainly any number of text editors make it now easy to go through and swap all symbols over to their corresponding HTML character entities. But this is rather a pain in the neck. You have to bring the code into one of those editors, select the entire text, and then execute whatever script you use to to the character conversion. It takes a little bit of time and when you are trying to get folks like our busy support team to also contribute blog entries, you want to reduce anything that adds time to the posting process.

What I was ideally trying to do for our authors was make it so that they could do something like this:

<code>
… XML code…
</code>

With something like this, they could simply copy/paste their XML code directly into the WPMU editor and… ta da… publish the post. In trying to make this ideal a reality, I worked my way through installing a number of different “code markup” plugins for WordPress:

I also looked at Code Viewer but really did not want to store the XML code in separate files.

I installed each of these (in some cases multiple times), read and re-read the instructions, added the appropriate markup (usually <code>) around the block of code, published the entries and…

Nothing.

All the posts looked horrible and didn’t display any of my XML code. This was all incredibly frustrating and after spending a sizable chunk of my time trying to make this work, I finally posted my problem on the WPMU Forum and soon received my answer.

It turns out that WordPress has a file called “kses.php” which lists all of the tags that are allowed inside my post. Any tags not in the allowed list get stripped out! This obviously occurs before the code markup plugins step in and do whatever conversion they do of the code into HTML character entities. So… all my XML code appears to WPMU as regular tags, which, because they aren’t listed in kses.php get stripped out.

Oops.

The end result is that it appears that I have two options:

1. Enter all the relevant VoiceXML, CCXML and CallXML tags into kses.php so that they are allowed; or
2. Keep on doing it the text editor massive replace route.

Given everything else on my plate, we’re going to reluctantly have to stick with #2 and just keep on replacing the symbols with HTML character entities before copying/pasting into WordPress’ editor. It’s a pain - but I don’t see an option until either I find another solution or get the time myself to update kses.php.

If anyone reading this knows of another option, I’d love to hear it.

Technorati Tags:
, , , , ,

Tags: , ,

One Response to “The challenge of embedding XML into a WordPress MU blog entry”

  1. Behind The Blog » Blog Archive » Enabling skype: and sip: URLs in WordPress MU 1.5.1 Says:

    [...] solution turned out to be similar to what I could do to solve my embedding XML problem… modify the kses.php file. There at line 338 was this: function wp_kses($string, [...]

Leave a Reply

Please note: By submitting a comment you agree to comply with our Comment Policy. We welcome all comments, positive or negative, but do reserve the right to remove all or part of blog comments that do not comply with our policy.