How to edit HTML/XML code syntax as content loaded in Xinha Editor

Written by - 0 comments

Published on - Listed in Internet HTML

I have been using Xinha editor for many years now in the background - and I'm still happy with it (although there are more powerful editors with more features available). However one thing which bugged me for a long time was the editing of content which contains example HTML or XML snippets. 

Such an example can be found on article ILO4 Firmware 1.20 changed the XML output, where an output of an XML file is showing up:

XML output shown as content of an article

However when this article is opened in Xinha (for example for modifying the content), the XML output disappears:

XML code disappeared in xinha editor

Why is this happening?

When new content is entered into the Xinha editor, typical code syntaxes (just as < and >) are entered as lt and gt characters:

Less than and greater than characters in xinha

This can be verified using the source code view of the editor:

Less than and greater than characters in xinha

This is also how the content is saved into the database.

However when Xinha loads such a content, it automatically translates &lt; and &gt; as "<" and ">" - they effectively become code and Xinha tries to display a (non-existing) code part. 

When looking at the source code view of the mentioned article above, this can be seen nicely:

Content read as XML code by Xinha

The question is now: How can Xinha be told to not translate these syntax characters into code characters?

Entize the data (content)

The Xinha FAQ has one specific article: Entize your data. From this page:

When you put HTML into a textarea to be turned into a Xinha editor, many people forget that raw HTML in a textarea is not valid, this leads to all sorts of unusual symptoms.

As the content is loaded in a textarea field, the output of the content is wrapped into the PHP function htmlspecialchars():

  <textarea required class="form-control" rows="50" id="iContent" name="iContent"><?php if (isset($iContent)) {echo htmlspecialchars($iContent);} ?></textarea>

Using this tells Xinha to not translate the special characters into code characters and the content (code) is preserved:

XML content preserved in Xinha

By looking at the source code view, the &lt and &gt characters are now preserved:

XML content preserved in Xinha

Add a comment

Show form to leave a comment

Comments (newest first)

No comments yet.