In the HTML file, I need to show some XML code. The problem is that I can't use
在HTML文件中,我需要显示一些XML代码。问题是我不能用
<pre>..</pre>
to show '<' and '>'.
显示'<'和'>'。
What would be the solution for this problem?
这个问题的解决方案是什么?
ADDED
From the answer, replacing '<' and '>' to <
and>
can be a solution. I'm an Emacs user, are there Emacs tools/magic to do that automatically? I mean, I can use search and replace, but I expect Emacs can do it by 'select region' -> 'M-x replace_xml' or something.
从答案开始,将'<'和'>'替换为<and>可能是一个解决方案。我是一个Emacs用户,有Emacs工具/魔法可以自动完成吗?我的意思是,我可以使用search和replace,但我希望Emacs可以通过'select region' -> 'M-x replace_xml'或其他方法实现这一点。
6 个解决方案
#1
5
You need to escape <
as <
and &
as &
. Optionally, for consistency, you can escape >
as >
你需要逃离< as <和和,。可选地,为了一致性,您可以将>转义为>
To do this automatically in Emacs, if you're in HTML mode, you can select the code that you would like to escape, and run M-x sgml-quote.
要在Emacs中自动执行此操作,如果您处于HTML模式,您可以选择要转义的代码,并运行M-x sgml-quote。
#2
2
You need to replace <
by <
and >
by >
. How to do this depends on the server side language in question.
你需要替换< by <并通过祝辞>。如何做到这一点取决于问题中的服务器端语言。
Update: as per your update: this is not programming related anymore. I think http://superuser.com is a better place to ask software related questions.
更新:根据您的更新:这不再与编程相关。我认为http://superuser.com是一个询问软件相关问题的好地方。
#3
1
As already mentioned, you need to escape the XML. For robustness I would also escape single and double quotes too. Note that CDATA
and <pre>
can cause you problems if, for any reason, your XML document includes ]]>
or </pre>
in it.
如前所述,您需要避开XML。对于健壮性,我还将避免使用单引号和双引号。注意,如果您的XML文档中包含[]>或,那么CDATA和
会导致问题。
You can get away with doing a straight string substitution for the escaping, but if you do, make sure you escape &
to &
before doing any of the other escapes.
你可以做一个直接的字符串替换来代替转义,但是如果你做了,确保你转义了& to &在做任何其他逃跑之前。
#4
0
As other have noted, you need to escape the xml markup to display it in html.
如前所述,您需要转义xml标记以在html中显示它。
Take a look at xmlverbatim stylesheet: It does that as well as pretty printing and colorizing.
看一下xml逐字样式表:它可以很好地进行打印和着色。
If you google around there are several stylesheets to do similar formatting.
如果您在谷歌附近有几个样式表来执行类似的格式化。
#5
0
- Select the region
- 选择该地区
- Do M-%
<
RET<
RET ! - 执行M-% < RET <受潮湿腐烂!
#6
0
Do a substitution using a programming language without Emacs.
使用没有Emacs的编程语言进行替换。
For Python:
Python:
#Make a copy just in case.
#Open file.
#Read lines.
for line in lines:
line = line.replace("<pre>", "<").replace("</pre>", ">")
#Output to file.
#Enjoy!
#1
5
You need to escape <
as <
and &
as &
. Optionally, for consistency, you can escape >
as >
你需要逃离< as <和和,。可选地,为了一致性,您可以将>转义为>
To do this automatically in Emacs, if you're in HTML mode, you can select the code that you would like to escape, and run M-x sgml-quote.
要在Emacs中自动执行此操作,如果您处于HTML模式,您可以选择要转义的代码,并运行M-x sgml-quote。
#2
2
You need to replace <
by <
and >
by >
. How to do this depends on the server side language in question.
你需要替换< by <并通过祝辞>。如何做到这一点取决于问题中的服务器端语言。
Update: as per your update: this is not programming related anymore. I think http://superuser.com is a better place to ask software related questions.
更新:根据您的更新:这不再与编程相关。我认为http://superuser.com是一个询问软件相关问题的好地方。
#3
1
As already mentioned, you need to escape the XML. For robustness I would also escape single and double quotes too. Note that CDATA
and <pre>
can cause you problems if, for any reason, your XML document includes ]]>
or </pre>
in it.
如前所述,您需要避开XML。对于健壮性,我还将避免使用单引号和双引号。注意,如果您的XML文档中包含[]>或,那么CDATA和
会导致问题。
You can get away with doing a straight string substitution for the escaping, but if you do, make sure you escape &
to &
before doing any of the other escapes.
你可以做一个直接的字符串替换来代替转义,但是如果你做了,确保你转义了& to &在做任何其他逃跑之前。
#4
0
As other have noted, you need to escape the xml markup to display it in html.
如前所述,您需要转义xml标记以在html中显示它。
Take a look at xmlverbatim stylesheet: It does that as well as pretty printing and colorizing.
看一下xml逐字样式表:它可以很好地进行打印和着色。
If you google around there are several stylesheets to do similar formatting.
如果您在谷歌附近有几个样式表来执行类似的格式化。
#5
0
- Select the region
- 选择该地区
- Do M-%
<
RET<
RET ! - 执行M-% < RET <受潮湿腐烂!
#6
0
Do a substitution using a programming language without Emacs.
使用没有Emacs的编程语言进行替换。
For Python:
Python:
#Make a copy just in case.
#Open file.
#Read lines.
for line in lines:
line = line.replace("<pre>", "<").replace("</pre>", ">")
#Output to file.
#Enjoy!