How to display XML source code using HTML with Emacs?

In the HTML file, I need to show some XML code. The problem is that I cannot use

<pre>..</pre> 

to show '<' and '>'.

What will be the solution to this problem?

ADDED

From the answer, replacing '<' and '>' to &lt; and &gt; may be a solution. I am an Emacs user, are there any Emacs / magic tools for this automatically? I mean, I can use search and replace, but I expect Emacs to be able to do this by choosing "select region" -> "Mx replace_xml" or something like that.

+4
source share
6 answers

You need to exit < like &lt; and & like &amp; . If you wish, for consistency you can avoid > like &gt;

To do this automatically in Emacs, if you are in HTML mode, you can select the code you would like to avoid and run Mx sgml-quote .

+5
source

You need to replace < with &lt; and > on &gt; . How to do this depends on the server side language.


Update : according to your update: this is no longer related to programming. I think http://superuser.com is the best place to ask questions related to software.

+2
source

As already mentioned, you need to avoid XML. For reliability, I would also avoid single and double quotes. Please note that CDATA and <pre> can cause problems if for any reason your XML document includes ]]> or </pre> .

You can get away with doing direct line substitution for escaping, but if you do, make sure you exit & in &amp; before you make any other screens.

+1
source

As already noted, you need to avoid xml markup in order to display it in html.

Check out the xmlverbatim stylesheet: it does this, as well as beautiful printing and coloring.

If you use google, there are several style sheets for similar formatting.

0
source

Make a replacement using a programming language without Emacs.

For Python:

 #Make a copy just in case. #Open file. #Read lines. for line in lines: line = line.replace("<pre>", "&lt;").replace("</pre>", "&gt;") #Output to file. #Enjoy! 
0
source
  • Choose region
  • Do M-% < RET &lt; RET !
0
source

All Articles