Not able to display XML in Wordpress post Not able to display XML in Wordpress post wordpress wordpress

Not able to display XML in Wordpress post


The wordpress codex has a whole page about writing code in your posts.

http://codex.wordpress.org/Writing_Code_in_Your_Posts

Their suggestion is to use html entity codes within <pre> or <code> tags

<family>    <dad>whatever</dad>    <mom>whatever</mom></family>

This could be tedious if you have a lot of code to show in your post. I suggest writing a small shortcode that would do this for you.

<?phpfunction xml_shortcode( $atts, $content ) {    return '<pre>' . htmlentities( $content ) . '</pre>';}add_shortcode( 'xml', `xml_shortcode` );?>

How to use your shortcode in a post

[xml]your code here[/xml]


If [sourcecode] is available but you cannot install additional plugins or add shortcodes (which is the case on wordpress.com), you have, to my knowledge, no other option than to encode the problematic characters before copying them.

Here are the detailed steps:

  1. Encode your snippet using an HTML encode, for instance using a free, online encoder
  2. edit your post in HTML mode
  3. add [sourcecode language="xml"]
  4. past the encoded source code
  5. add [/sourcecode]


I suffered from this problem recently.
For me what worked was to enter the code in text mode. Selection of code. Application of code formatting from the Format menu.

Later, I used the crayon syntax highlight plugin. The plugin works well, you have to follow the same process as above with the only difference that instead of code formatting option, choose the crayon option after selecting the code to highlight.

You can check the highlighting here