如何在 XML 中转义“&”?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12524908/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-06 13:41:37  来源:igfitidea点击:

How to escape "&" in XML?

xml

提问by herbertD

I write

我写的

 <string name="magazine">Newspaper & Magazines</string>

in strings.xml

在strings.xml中

But the Compiler says:

但是编译器说:

The entity name must immediately follow the '&' in the entity reference.    strings.xml /OOReaderWidget/res/values  line 9  Android XML Format Problem

So how Can I show a "&" in strings.xml? Thanks!

那么如何在strings.xml 中显示“&”?谢谢!

回答by Ram kiran

use &amp;in place of &

&amp;代替使用&

change to

改成

<string name="magazine">Newspaper &amp; Magazines</string>

回答by xshoppyx

'&' --> '&amp;'

'<' --> '&lt;'

'>' --> '&gt;'