XML earns its keep where strict structure, validation, and rich tooling matter more than compactness. Document-heavy formats lean on it: DOCX and XLSX files are zipped XML, SVG is XML, and SAML assertions for enterprise single sign-on are XML. If you need schema validation, namespaces, mixed content (text interleaved with tags), or attributes versus elements, XML gives you all of it natively.
The cost is verbosity and complexity. Every value is wrapped in an open and close tag, so XML payloads are typically larger than the equivalent JSON, often by 30 percent or more. Parsing is heavier, and the surrounding stack (XSD, XSLT, XPath, SOAP envelopes) has a real learning curve. XML parsers have also been a classic security target through the XXE (XML External Entity) attack, so external entity resolution should be disabled.
For most web and mobile APIs built after roughly 2015, JSON won because it is lighter, maps directly onto JavaScript objects, and needs no extra tooling. Reach for XML when you are integrating with SOAP services, parsing office documents, working with SVG, or talking to enterprise and government systems that standardized on it years ago.