Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
369 views
in Technique[技术] by (71.8m points)

html - 如何将XML中的&符号转义为HTML中的实体?(How do I escape ampersands in XML so they are rendered as entities in HTML?)

I have some XML text that I wish to render in an HTML page.

(我有一些XML文本希望在HTML页面中呈现。)

This text contains an ampersand, which I want to render in its entity representation: &

(这段文本包含一个&符号,我想以其实体表示形式呈现&)

.

(。)

How do I escape this ampersand in the source XML?

(如何在源XML中转义此“&”号?)

I tried &

(我试着&)

, but this is decoded as the actual ampersand character ( & ), which is invalid in HTML .

(,但这被解码为实际的&字符( & ), 在HTML中无效 。)

So I want to escape it in such a way that it will be rendered as &

(因此,我想以将其呈现为&的方式对其进行转义&)

in the web page that uses the XML output.

(在使用XML输出的网页中。)

  ask by AJM translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

When your XML contains &

(当您的XML包含&)

, this will result in the text &

(,这将导致文本&)

.

(。)

When you use that in HTML, that will be rendered as & .

(当您在HTML中使用该代码时,该代码将显示为& 。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...