字符串资源xml中的URL [英] URL in String resource xml

查看:60
本文介绍了字符串资源xml中的URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在 strings.xml 文件中存储了两个网址.我想存储它们而不对它们进行编码(作为原始文本),但是 strings.xml 会为 = & 引发错误.

I have stored a couple of urls in strings.xml file. I want to store them without encoding them (as raw text), but strings.xml throws error for = and &.

例如:

http://www.example.org/index.php?p=616687&ac=some_q

如果我按原样存储链接,它将抛出错误:

If I store the link as it is, it will throw the error:

The reference to entity "ac" must end with the ';' delimiter.

但是,如果我将& 替换为%26 :

However, if I replace the & with %26:

http://www.example.org/index.php?p=616687%26ac=some_q

虽然可以正常运行,但不会在浏览器中打开正确的页面.

while this works without any error, this doesn't open the correct page in the browser.

是否可以通过任何方式将链接存储在 strings.xml 中而不进行格式化或uri编码?

Is there any way I can store the links in strings.xml as it is without formatting or uri encoding them?

推荐答案

您不能直接使用& ,因为XML文档应该是

You cannot use & directly, because XML document is expected to be well-formed and the problem is with & character itself. For XML/HTML you would have to use & entity (or &), but for URL use URL encoding and replace & it with %26 (as you did) which should simply work as browsers do understand such things as they simply have to.

这篇关于字符串资源xml中的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆