Reapping string in XML

4

Eg:

<?xml version="1.0" encoding="utf-8"?>
<resources>
   <string name="primeiro_nome">Bigown</string>
   <string name="nome_completo">{primeiro nome} Silva</string>
</resources>

Is it possible to reuse the string first_name in the string below in the xml?

    
asked by anonymous 27.07.2015 / 04:08

2 answers

1
  

Just as a remark I have not tested this directly with the Android SDK, but I use it with Xamarin and it's working perfectly for me

You can declare new entities in your XML to be able to reuse text, making it easier to update certain values that are repeated, I am using it as follows

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE resources [
    <!ENTITY telefone "(12) 3456 7890">
    <!ENTITY site "http://www.meusite.com.br">
]>
<resources>
    <string name="contato">Entre em contato com o nosso suporte pelo telefone &telefone;</string>
    <string name="saibamais">Conheça mais sobre o nosso produto visitando no website &site;.</string>
</resources>

Notice that in XML I declare an entity called telefone , and it is used as &telefone; in XML

    
28.07.2015 / 14:04
0

To copy the value of one element into another you need to use XSLT and use the < xsl:copy-of select="$NOME_DO_ELEMENTO_COPIADO" /> statement

The example you passed would look like this:

<?xml version="1.0" encoding="UTF-8"?>
  <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<resources> 
    <string name="primeiro_nome">Bigown</string> 
    <string name="nome_completo"><xsl:copy-of select="$primeiro_nome" /> Silva</string> 
</resources>

The full documentation for reference is on link

    
27.07.2015 / 04:17