Chapter 20: XML Server
XML on the server — written as if I’m sitting next to you, explaining step by step like a patient teacher who wants you to really understand how XML is actually used on server-side systems in real projects (even in 2025–2026).
We will go slowly and cover the most common and realistic scenarios:
- Why XML is still used on servers (despite JSON dominance)
- The main roles XML plays on the server
- Typical server-side workflows
- Concrete examples in different languages/contexts
- Modern patterns vs legacy patterns
Let’s begin.
1. Why is XML still used on the server in 2025–2026?
Even though JSON is the dominant format for new APIs, XML continues to be very important on servers for several strong reasons:
| Reason | Typical situations / industries | Still very active in 2025–2026? |
|---|---|---|
| Legacy systems & integration | Banks, insurance, ERP, government, telecom, healthcare | Very much so |
| Mandatory standards | SOAP web services, EDI (EDIFACT, X12), e-Invoicing (UBL, PEPPOL, GST India), ISO 20022, HL7 CDA | Extremely common |
| Strong schema validation requirement | Financial messages, legal documents, medical records | Very strong |
| Very large documents + streaming processing | Batch invoices, customs declarations, catalog feeds | Yes (StAX, SAX, XmlReader…) |
| Mixed content & document-oriented data | Publishing (DocBook, DITA), office formats (OOXML) | Still used |
| Some companies just never migrated | Many enterprise Java, .NET, SAP systems | Common |
Bottom line: If you work with enterprise software, financial systems, government portals, healthcare, or legacy integration, you will meet XML on the server — often a lot of it.
2. Most Common Ways XML is Used on the Server
| # | Use Case | Typical technology stack | Input / Output ? | Most common today? |
|---|---|---|---|---|
| 1 | SOAP Web Services | Java (JAX-WS), .NET (WCF), PHP (SoapServer) | Both | Still very common |
| 2 | REST API that returns XML | Spring Boot, ASP.NET Core, Express.js | Mostly output | Declining but exists |
| 3 | File-based integration (batch) | Spring Batch, Apache Camel, custom scripts | Input + Output | Very common |
| 4 | e-Invoicing / e-Document exchange | Custom middleware, SAP, Oracle, Tally, ClearTax | Input + Output | Extremely active |
| 5 | Configuration files | Spring, Java EE, Apache Tomcat, JBoss | Input | Still used |
| 6 | Report generation (XML → PDF/HTML) | XSLT + Apache FOP, Flying Saucer, iText | Input → transformed | Common |
3. Realistic Example 1 – SOAP Web Service (very common legacy & enterprise case)
Server receives and returns XML
Typical SOAP request (XML input)
|
0 1 2 3 4 5 6 7 8 9 10 11 12 13 |
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"> <soap:Body> <ns:getBalance xmlns:ns="http://bank.example.com"> <ns:accountNumber>ACC-784512</ns:accountNumber> <ns:currency>INR</ns:currency> </ns:getBalance> </soap:Body> </soap:Envelope> |
Server code – Java Spring Boot + JAX-WS style (simplified)
|
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
import jakarta.xml.bind.annotation.*; @WebService public class AccountService { @WebMethod public BalanceResponse getBalance( @WebParam(name = "accountNumber") String accountNumber, @WebParam(name = "currency") String currency) { // Real business logic would go here BigDecimal balance = lookupBalance(accountNumber); BalanceResponse response = new BalanceResponse(); response.setAccountNumber(accountNumber); response.setBalance(balance); response.setCurrency(currency); return response; } } |
Generated XML response (automatic via JAXB)
|
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"> <soap:Body> <ns:getBalanceResponse xmlns:ns="http://bank.example.com"> <ns:accountNumber>ACC-784512</ns:accountNumber> <ns:balance>47892.50</ns:balance> <ns:currency>INR</ns:currency> <ns:status>ACTIVE</ns:status> </ns:getBalanceResponse> </soap:Body> </soap:Envelope> |
Key point: The server never manually builds XML strings — modern frameworks (JAX-WS, Spring WS, .NET WCF, Apache CXF…) use JAXB, Jackson XML, or similar to automatically convert objects ↔ XML.
4. Realistic Example 2 – REST API that returns XML (still exists)
Spring Boot controller returning XML
|
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
@RestController @RequestMapping("/api/v1") public class ProductController { @GetMapping(value = "/products/{id}", produces = {MediaType.APPLICATION_XML_VALUE}) public Product getProduct(@PathVariable String id) { Product p = productService.findById(id); if (p == null) { throw new ResponseStatusException(HttpStatus.NOT_FOUND); } return p; } } |
Corresponding model class (JAXB annotated)
|
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
@XmlRootElement(name = "product") @XmlAccessorType(XmlAccessType.FIELD) public class Product { @XmlAttribute private String id; @XmlElement private String name; @XmlElement private BigDecimal price; @XmlElement(name = "currency") private String currency = "INR"; // getters & setters } |
Output XML when calling /api/v1/products/P-784512
|
0 1 2 3 4 5 6 7 8 9 10 |
<product id="P-784512"> <name>Wireless Noise-Cancelling Headphones</name> <price>8499.00</price> <currency>INR</currency> </product> |
Key point: Even in REST APIs, some clients (especially enterprise / government / legacy systems) still demand XML instead of JSON.
5. Realistic Example 3 – Processing large incoming XML file (batch / file integration)
Common scenario: A bank or customs department receives large XML files (thousands of invoices, declarations…)
Typical server-side processing (Java + StAX – streaming)
|
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
public void processLargeInvoiceFile(Path xmlFile) throws Exception { XMLInputFactory factory = XMLInputFactory.newInstance(); XMLStreamReader reader = factory.createXMLStreamReader(Files.newInputStream(xmlFile)); while (reader.hasNext()) { int event = reader.next(); if (event == XMLStreamReader.START_ELEMENT) { String localName = reader.getLocalName(); if ("invoice".equals(localName)) { String number = reader.getAttributeValue(null, "number"); // Start processing one invoice Invoice inv = new Invoice(number); // ... parse children using reader.getElementText(), etc. } } } } |
Why streaming (StAX / SAX / XmlReader) instead of DOM?
- Files can be several GB
- DOM would load everything → OutOfMemoryError
- Streaming → constant low memory usage
6. Quick Summary – XML on the Server in 2025–2026
| Role / Usage | Most common technologies | JSON or XML? | Typical server language |
|---|---|---|---|
| SOAP Web Services | JAX-WS, Spring WS, Apache CXF, .NET WCF | XML | Java, C# |
| REST API with XML support | Spring Boot, ASP.NET Core, FastAPI + xmltodict | JSON + XML | Java, C#, Python |
| Batch / file exchange | Spring Batch, Apache Camel, custom scripts | XML | Java, Python, C# |
| e-Invoicing / government exchange | Custom middleware, SAP, Tally, ClearTax, NIC | XML (UBL, GST format) | Java, .NET, Python |
| Legacy configuration | Spring, Java EE, Apache Tomcat | XML | Java |
| Report generation (XML → PDF / HTML) | XSLT + FOP, Docx4j, Flying Saucer | XML → other formats | Java, .NET |
Most realistic advice in 2025–2026:
- If you are starting a new project → prefer JSON unless forced by standard
- If you work in enterprise / finance / government / healthcare / logistics → you will meet XML very often
- Learn to read, generate, validate, and transform XML — especially streaming techniques
Would you like to go deeper into any of these directions?
- Creating a complete SOAP service example
- Processing large XML files (real batch example)
- Modern Spring Boot with both JSON and XML endpoints
- How GST e-invoice XML is handled on server in India
- Generating PDF from XML (XSLT + FOP example)
- Migrating old XML services to JSON (common patterns)
Tell me what interests you most right now! 😊
