Avoiding Double Encoding in Android XML

// Guides

Avoiding Double Encoding in Android XML

Fix Android strings.xml double encoding — keep xliff:g tags, HTML entities, and inline markup stable across localization parse and write-back cycles.

Android XML often mixes plain text with inline tags and entities. Double encoding can break UI text rendering.

Common Symptoms

Double encoding usually appears as:

  • < or > showing in app UI.
  • Markup fragments rendering as literal text.
  • Strings changing after repeated parse/write cycles.

Safe Practices

  • Keep inline tags as XML markup where possible (<em>, <xliff:g>).
  • Avoid manually escaping the same value multiple times.
  • Validate output after round-trip parse/write flows.

Practical Workflow

  1. Keep source XML valid and parser-friendly.
  2. Run sync and inspect generated Android resource output.
  3. Spot-check strings containing entities and inline markup.
  4. If output changed unexpectedly, compare source vs generated value and remove duplicate manual escaping.

Built-In Protections

String Catalog writer:

  • Escapes only bare ampersands.
  • Preserves inline markup fragments.
  • Avoids turning &lt;...&gt; into &amp;lt;...&amp;gt; during standard round trips.

Expected Outcome

You should get Android app localization output that preserves intended entities and inline tags without cumulative escaping artifacts.

Common Mistakes

  • Mixing pre-escaped and raw forms of the same token across files.
  • Editing generated XML and re-escaping content by hand.
  • Treating inline markup as plain text in source values.