Scrivio Interview library
LeadershipAdvanced5 min read · updated 12 November 2026

Your organisation has XML integrations built over 20 years with DOM, SAX, StAX, JAXB, XStream and hand-written string concatenation. How would you standardise XML handling across teams?

I would publish a short list of approved approaches, StAX for streaming, Jakarta XML Binding or Jackson XML for mapping to objects, and DOM with XPath for small documents, and back it with a shared library whose factories are configured securely so every team gets XXE protection by default. XStream on untrusted input and XML built by string concatenation would be retired, javax.xml.bind code moved to jakarta.xml.bind as part of the Jakarta EE migration, and progress tracked with dependency scanning and code search, starting with internet-facing services.

Why this question is asked

When a company has twenty years of integrations, every generation of developers leaves its favourite XML library behind. The variety itself is a cost: each library has its own security settings, upgrade path and failure modes, and nobody can review all of them. Interviewers ask this leadership question to see whether we can set a standard that teams actually adopt, rather than a document nobody reads. In this answer, we will look at why the zoo of approaches is a risk, choose the approved set and the reasons for each, decide what to retire, design the shared library that makes the safe way the easy way, plan the JAXB to Jakarta move, and track the migration.

1Why Many Approaches Are a Risk

Six approaches mean six sets of defaults. DOM, SAX and StAX each need their own settings to block XML external entities (XXE), the attack where a document's DTD makes the parser read local files or call internal URLs. XStream, a library that turns XML into arbitrary Java objects, has a long history of deserialisation vulnerabilities in which crafted input makes it instantiate dangerous classes. Hand-written string concatenation produces invalid XML the first time a customer is called Smith & Sons, and can be abused for injection.

The aim of standardising is not elegance. It is to reduce the number of things the security team must check, the number of skills engineers must learn, and the number of libraries we must patch.

2Choosing the Approved Set

A standard works when it is small and each option has a clear reason to exist. Three approaches cover nearly every case.

Approved XML approaches
NeedApproved approachReason
Large files, streaming read or writeStAX (XMLStreamReader, XMLStreamWriter)constant memory, readable pull model
Map XML to Java objectsJakarta XML Binding or Jackson XMLtyped objects, XSD support, little code
Small documents, ad hoc queriesDOM plus XPathbuilt into the JDK, easy navigation
Existing SAX pipelinesallowed, not for new codeno value in rewriting working filters
XStream on untrusted inputretirehistory of deserialisation flaws
String concatenationbannedno escaping, invalid or injectable XML

Notice that SAX is tolerated rather than banned. Rewriting stable SAX handlers has a cost and little benefit, so the rule is simply that new code uses the approved set. A standard that demands rewrites of working code loses the support of teams quickly.

3The Shared Library: Making the Safe Way the Easy Way

The most effective part of the standard is not the document; it is a small internal library that hands out correctly configured factories. If every team calls SafeXml.documentBuilder() instead of DocumentBuilderFactory.newInstance(), every team gets XXE protection without having to know the details.

Java
public final class SafeXml {
public static DocumentBuilder documentBuilder() throws ParserConfigurationException {
DocumentBuilderFactory f = DocumentBuilderFactory.newInstance();
f.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
f.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
f.setXIncludeAware(false);
f.setExpandEntityReferences(false);
f.setNamespaceAware(true);
return f.newDocumentBuilder();
}
public static XMLInputFactory inputFactory() {
XMLInputFactory f = XMLInputFactory.newFactory();
f.setProperty(XMLInputFactory.SUPPORT_DTD, false);
f.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
return f;
}
// also: saxParser(), transformerFactory(), schemaFactory(), xpath()
}

We pair the library with an automated rule, for example a static analysis or ArchUnit test, that flags direct calls to the raw factories outside it. The library also gives us one place to change settings when a new attack or a JDK change appears, instead of fifty.

4Moving JAXB Code to Jakarta XML Binding

JAXB, the javax.xml.bind API, used to ship with the JDK. It was deprecated in Java 9 and removed in Java 11, and the Jakarta EE 9 release renamed its packages to jakarta.xml.bind. Spring Boot 3 and later, and Jakarta EE 10 and 11 servers, expect the jakarta packages. So old JAXB code needs new dependencies (jakarta.xml.bind-api plus an implementation such as org.glassfish.jaxb:jaxb-runtime), new imports and regenerated classes from XSDs.

This should not be a separate project. The renaming is part of every service's Spring Boot 3 or Jakarta EE upgrade, so we add it to that migration plan and provide a recipe: tools such as OpenRewrite have recipes for the javax to jakarta change, and the shared library documents the dependency versions to use.

5Tracking the Migration

We need to know where we are. Dependency scanning across all repositories shows which services still pull in XStream, old dom4j or JDOM versions, or the javax.xml.bind API; code search finds direct factory calls and string-built XML patterns such as "<" + tag. We publish the counts per team on a dashboard and review them monthly.

Order matters. Internet-facing services that accept XML from outside go first, because that is where XXE and deserialisation attacks arrive. Internal batch jobs reading trusted files come later, and we accept that some stable legacy code may stay as it is with only the secure configuration added.

Step throughRolling out the XML standard
  1. Publish the approved set and the reason for eachone page, with examples
  2. Release the shared SafeXml librarysecure factories by default
  3. Scan dependencies and search codefind XStream, javax.xml.bind, raw factories
  4. Accepts external XML?
    YesFix first, within a quarterNoSchedule with the next upgrade
  5. Add a build rule against raw factoriesstops new drift
  6. Review the dashboard monthlycounts per team

6 steps in order. Play them, or step through them one at a time.

6Follow-up questions

What would you do with a team that insists on XStream?

I would ask what it gives them. Often it is convenience for internal object snapshots, which Jakarta XML Binding or Jackson can do. If XStream must stay for trusted internal data, it must be a current version with an explicit allowlist of permitted types, and it must never parse input from outside. That exception is written down with an owner and a review date.

How do you get teams to adopt the standard rather than ignore it?

Make it the easiest path: a library that is simpler to use than the raw APIs, examples for the common tasks, and a build rule that catches new violations early. Involve senior engineers from several teams in choosing the set so it is not seen as imposed, and do not demand rewrites of working code that is safe.

Is Jackson XML or Jakarta XML Binding the better default?

Jakarta XML Binding is the better choice when we work from partner XSDs and need precise control of namespaces and schema features. Jackson XML suits teams that already use Jackson for JSON and want the same annotations and objects for simple XML. Allowing both, with that guidance, is reasonable.

7Conclusion

In this answer, we standardised XML handling by approving a small set of approaches, StAX for streaming, Jakarta XML Binding or Jackson XML for binding and DOM with XPath for small documents, while retiring XStream for untrusted input and banning XML built by string concatenation. A shared library with secure factory settings gives every team XXE protection by default, the javax.xml.bind to jakarta.xml.bind move rides on the Jakarta EE upgrade because JAXB left the JDK in Java 11, and dependency scanning and code search track progress, internet-facing services first.

What to say in the interviewAbout 80 seconds aloud

Open with

I would start by making the choice small and explicit. New code uses one of three approaches: StAX when we stream large files, Jakarta XML Binding or Jackson XML when we map XML to objects, and DOM with XPath for small documents.

Then, if they want more

Existing SAX pipelines can stay. Two things go away: XStream for anything that parses untrusted input, because of its long history of deserialisation vulnerabilities, and building XML by string concatenation, because it breaks on the first ampersand and can be injected.

The part that really changes behaviour is a shared library that hands out safely configured factories, doctype declarations disallowed, external entities off, secure processing on, so every team gets XXE protection without knowing the details, plus a build rule that flags direct use of the raw factories.

For JAXB, the javax.xml.bind API was removed from the JDK in Java 11 and renamed to jakarta.xml.bind in Jakarta EE 9, so I would fold that migration into each service's Spring Boot 3 or Jakarta EE upgrade with a recipe.

Finally, I would scan dependencies and search code across all repositories, put the counts on a dashboard, and fix internet-facing services that accept XML first, then the rest with their normal upgrades.

About this answer

Last updated
12 November 2026
Versions it names
Java 11, Spring Boot 3, Jakarta EE 10, Jakarta EE 9
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Your organisation has XML integrations built over 20 years with DOM, SAX, StAX, JAXB...": https://scrivio-interview-library.netlify.app/java/xml-processing/704aa9ea91/