How to Translate an XML File Without Breaking Tags (2026)
EqualangIn brief
Translate XML text nodes while keeping tags, attributes, and entities valid. Use an XLSX extract-and-merge workflow or a Python ElementTree script.
Keywords: translate xml file; translate xml file online; translate xml file free; translate xml file to english; android strings.xml translation
To translate an .xml file without corrupting its structure, you have to separate the human-readable text nodes from the surrounding markup before sending anything to a translator. Equalang Document Translation (/documents) accepts HTML, PDF, DOCX, PPTX, XLSX, EPUB, and TXT—it does not accept .xml files directly. Instead of pasting raw XML into a text box (which often translates tag names and breaks parsers), you can either extract your text nodes into a two-column .xlsx workbook, translate the sheet through /documents, and write the strings back with a real XML parser, or run a short Python xml.etree.ElementTree script that translates only designated tags and re-serializes valid XML automatically.
Why Pasting Raw XML into a Text Translator Breaks Your Build
Under the W3C Extensible Markup Language (XML) specification, an XML parser rejects an entire file the moment a single syntax rule is violated. Unlike browsers that try to guess around broken HTML, XML tools used in Android builds, e-commerce product feeds, and DITA/DocBook documentation enforce strict structural validation:
- Mismatched opening and closing tags: Every
<element attr="id">must close with the exact same case-sensitive</element>. Plain-text translators routinely translate tag names (turning<price>into<preis>or<title>into<titel>) or inject spaces after the slash (</ string>), causing an immediate fatal parse error. - Corrupted attributes and IDs: Machine-read attributes such as
name="checkout_btn"ortranslatable="false"look like ordinary words to a plain-text prompt. If a translator localizes an attribute key or value, your application code can no longer look up the resource ID. - Unescaped reserved characters: Literal
&,<, and>characters inside text nodes must be encoded as XML entities (&,<,>). When a generic text translator decodes&back into a raw&—or inserts spacing like& amp;—the output stops being well-formed XML.
Because XML schemas vary wildly—from Android strings.xml resource lists to deeply nested product catalogs—no single drag-and-drop translator knows which tags hold display copy and which hold database keys unless you isolate the translatable nodes first.
Workflow 1: Extract XML Text to XLSX, Translate Once, and Write Back
When you need to translate an Android strings.xml file, a multi-thousand-item product feed, or a localization bundle online without writing API retry logic, converting the translatable nodes into a two-column .xlsx file (xpath_or_key | source_text) is the safest route.
In this workflow, your XML tags, attributes, and entity escapes never touch the translation engine. Better yet, when you upload an .xlsx file to Equalang Document Translation, repeated text cells across the sheet are translated and billed only once, while pure numbers and formulas are skipped and written back as-is. Document translation currently covers Chinese, English, Japanese, Korean, Spanish, French and other languages (see /pricing).

Step 1: Extract translatable XML nodes into a two-column .xlsx
Use Python's built-in xml.etree.ElementTree module together with openpyxl to pull only the text nodes you want translated. The script below reads an Android-style strings.xml file, skips any <string> tag marked translatable="false", and writes the resource key and source text into to_translate.xlsx.
import xml.etree.ElementTree as ET
from openpyxl import Workbook
tree = ET.parse("strings.xml")
root = tree.getroot()
wb = Workbook()
ws = wb.active
ws.title = "xml_strings"
ws.append(["key", "text"])
for elem in root.findall("string"):
if elem.get("translatable") == "false":
continue
key = elem.get("name")
if key and elem.text:
# Prefix the key with an apostrophe or keep it in column A
# while you compare or copy only the translated text column
ws.append([key, elem.text])
wb.save("to_translate.xlsx")
If you are working with a nested product feed (for example, <item> nodes containing <title> and <description>), you can store an indexed XPath such as .//item[1]/title in column A and the text content in column B. To prevent your key column from being translated at all, you can also upload a single-column .xlsx containing only source_text, keeping the row-to-key mapping in your local two-column file.
Step 2: Upload the .xlsx to Equalang Document Translation
Open /documents, upload your .xlsx file, and pick your target language (for example, translating a regional XML feed to English or localizing an English strings.xml into German or Japanese). The web uploader processes one file per upload—you can queue files one after another without limit, and each account runs up to 3 documents concurrently while the rest wait in the queue.
Once the job finishes, you can inspect the source and translated sheets side by side in the Translation workspace or download the translated .xlsx directly. If your project stores localization strings in JSON or CSV rather than XML, see our guides on how to translate a JSON file and how to translate a CSV file.
Step 3: Merge the translated strings back into valid XML
Read the translated .xlsx column and assign each string back to its matching <string> node in the original XML tree. Because ElementTree handles serialization, any &, <, or > in the translated copy is automatically escaped back into &, <, and >.
import xml.etree.ElementTree as ET
from openpyxl import load_workbook
# Load the original XML and the translated XLSX
tree = ET.parse("strings.xml")
root = tree.getroot()
wb_orig = load_workbook("to_translate.xlsx")
ws_orig = wb_orig["xml_strings"]
wb_trans = load_workbook("to_translate_translated.xlsx")
ws_trans = wb_trans["xml_strings"]
# Map original keys from column A to translated text from column B
translations = {}
for orig_row, trans_row in zip(
ws_orig.iter_rows(min_row=2, values_only=True),
ws_trans.iter_rows(min_row=2, values_only=True),
):
key = orig_row[0]
translated_text = trans_row[1]
if key and translated_text is not None:
translations[key] = str(translated_text)
for elem in root.findall("string"):
if elem.get("translatable") == "false":
continue
key = elem.get("name")
if key in translations:
elem.text = translations[key]
tree.write("strings_translated.xml", encoding="utf-8", xml_declaration=True)
Limitations to watch out for
- Inline child tags (
elem.tail): Inxml.etree.ElementTree, if a paragraph contains inline markup such as<p>Click <b>Save</b> to continue</p>,elem.textonly captures"Click ", while" to continue"lives on the child<b>element's.tailproperty. For DITA or DocBook files heavy with inline formatting tags (<b>,<i>,<xref>), rename or wrap the snippet as valid.html—which/documentsaccepts directly and translates while keeping inline styling intact—rather than flattening.textand.tailinto spreadsheet rows. <![CDATA[...]]>blocks and XML comments: StandardElementTree.parse()strips XML comments and converts CDATA sections into regular escaped text on.write(). If your target parser strictly requires preserved comments or literal<![CDATA[...]]>wrappers, parse withlxml.etreeusingstrip_cdata=False.- Android apostrophe escaping: Android's AAPT compiler requires single quotes inside
strings.xmlto be escaped as\'or wrapped in double quotes. Run a quick.replace("'", "\\'")on translated strings before writing Android XML resources.
Workflow 2: Direct Python ElementTree Script for Automated Pipelines
If you translate .xml files inside a CI/CD pipeline or prefer not to export an intermediate .xlsx file, you can iterate over the XML tree directly in Python and call a text translation endpoint (such as the Equalang API documented at /developers) for each unique text value.
Adding a simple in-memory dictionary (cache = {}) in your script ensures that identical status labels or category names across a large XML feed are only sent over the network once:
import xml.etree.ElementTree as ET
def translate_text(text: str, target_lang: str) -> str:
# Replace with your HTTP call to the Equalang API (/developers)
# or your preferred translation function
raise NotImplementedError("Connect your translation API call here")
def translate_xml_file(input_path: str, output_path: str, target_lang: str):
tree = ET.parse(input_path)
root = tree.getroot()
seen = {}
# Adjust the tag selector to match your schema, e.g. ".//string" or ".//description"
for elem in root.findall(".//string"):
if elem.get("translatable") == "false":
continue
source = (elem.text or "").strip()
if not source:
continue
if source not in seen:
seen[source] = translate_text(source, target_lang)
elem.text = seen[source]
# ElementTree automatically escapes &, <, and > and writes the UTF-8 header
tree.write(output_path, encoding="utf-8", xml_declaration=True)
After generating the translated XML file, always validate it before committing or deploying. Running python3 -c "import xml.etree.ElementTree as ET; ET.parse('strings_translated.xml')" in your terminal confirms in a fraction of a second that every tag closes properly and every entity is valid.
Frequently Asked Questions
Can I upload an .xml file directly to Equalang Document Translation?
No. Equalang Document Translation (/documents) supports PDF, DOCX, PPTX, XLSX, EPUB, HTML, and TXT, along with SRT/VTT subtitles, images, and audio/video files. To translate an .xml file through /documents, extract the translatable text nodes into an .xlsx sheet first, translate the .xlsx, and write the translated cells back into your XML structure.
How can I translate an XML file online for free?
Python's xml.etree.ElementTree parser is free and built into every standard Python installation, so extracting and re-merging XML text nodes costs nothing. For the translation step, you can process the extracted .xlsx strings through a free-tier translation API or offline model before running the write-back script.
How do I prevent XML tags, attributes, and %1$s placeholders from breaking?
Never send raw <tag> markup to a plain-text translator. Parse the XML file with a compliant parser (xml.etree.ElementTree), filter out non-translatable nodes (such as translatable="false"), extract only the inner text strings, and let the parser's .write() method re-encode &, <, and > when building the translated .xml file.