问题描述
我想知道是否有一种方法可以插入/注入<字符串>
在一个XML文件中定义为另一种元素&lt ;字符串>
元素,这样做只是使用XML
I would like to know whether there is a way to insert/inject a <string>
element defined in an XML file into another <string>
element, doing that just with XML.
例如我可以有:
<string name="author">Francesco</string>`
和我期待的是这样的:
<string name="about_application">Author: @string/author</string>`
让的getString(R.string.about_application)
将导致作者:弗朗西斯。
so that getString(R.string.about_application)
would result in "Author: Francesco".
我知道我可以结合使用Java中的code中的两个元素的String.Format(字符串,formatArgs)
例如像:
I know that I could combine the two elements in Java code using String.format(string, formatArgs)
like for example:
<string name="author">Francesco</string>
<string name="about_application">Author: %1$s</string>`
,然后在code使用
and then in code use
String.format(getString(R.string.about_application), getString(R.string.author))
但我想直接做在XML。
but I would like to do it in XML directly.
任何人都可以给我建议的方式来做到这一点?
Can anyone suggest me a way to do it?
推荐答案
如果我理解你在找什么做的,然后点击的 可能会帮助你达到你所期待的。
If I understand what you are looking to do, then internal (parsed) general entities might help you achieve what you are looking for.
对如何定义值弗朗西斯作为一个实体名为身份验证,然后一个例子使用它在你的XML:
An example of how you can define the value "Francesco" as an entity called "auth" and then use it in your XML:
<?xml version="1.0"?>
<!DOCTYPE doc [
<!ENTITY auth "Francesco">
]>
<doc>
<string name="author">&auth;</string>
<string name="about_application">Author: &auth;</string>
</doc>
在由XML解析器读取,该文件将被解析和评估,或看见,因为:
When read by an XML parser, the document will be parsed and evaluated, or "seen", as:
<?xml version="1.0"?>
<doc>
<string name="author">Francesco</string>
<string name="about_application">Author: Francesco</string>
</doc>
这篇关于Android的:如何注入&LT;字符串&GT;元到另一个&LT;字符串&GT;在XML元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!