XML and Web Services

Web services are software systems that allow different applications — running on different machines, written in different languages — to communicate over the internet. XML is the language many web services use to describe, request, and deliver data. Whether it is a payment gateway, a weather API, or a banking system, XML-based web services power critical infrastructure worldwide.

What Makes XML Ideal for Web Services

  • Platform-independent: A Java server and a Python client exchange XML without compatibility issues.
  • Human-readable: Developers can inspect XML messages in plain text to debug problems.
  • Self-describing: Element names explain what the data means.
  • Validated: Schemas ensure both sides agree on the data structure before processing begins.

The Web Services Stack

+---------------------------+
|   Business Application    |  ← Your application logic
+---------------------------+
           |
+---------------------------+
|   SOAP / REST + XML       |  ← Communication protocol
+---------------------------+
           |
+---------------------------+
|   WSDL (Description)      |  ← Service contract definition
+---------------------------+
           |
+---------------------------+
|   HTTP / HTTPS            |  ← Transport layer
+---------------------------+

WSDL — Web Services Description Language

WSDL is an XML-based language that describes a web service. It defines what operations the service offers, what data each operation expects, and what data it returns. Think of WSDL as a restaurant menu — it tells you what dishes are available (operations) and what ingredients go into each dish (parameters).

Simplified WSDL Structure

<definitions name="CurrencyService"
  targetNamespace="http://exchange.example.com/"
  xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">

  <types>
    <!-- XML Schema defining request and response types -->
  </types>

  <message name="ConvertRequest">
    <part name="fromCurrency" type="xsd:string"/>
    <part name="toCurrency"   type="xsd:string"/>
    <part name="amount"       type="xsd:decimal"/>
  </message>

  <message name="ConvertResponse">
    <part name="result" type="xsd:decimal"/>
  </message>

  <portType name="CurrencyPortType">
    <operation name="Convert">
      <input  message="tns:ConvertRequest"/>
      <output message="tns:ConvertResponse"/>
    </operation>
  </portType>

</definitions>

REST with XML

REST APIs commonly use JSON today, but XML remains standard in enterprise and government systems. A REST API with XML sends XML in the HTTP body and uses standard HTTP methods.

HTTP POST Request Body

POST /api/orders HTTP/1.1
Content-Type: application/xml

<?xml version="1.0" encoding="UTF-8"?>
<order>
  <customerId>C1042</customerId>
  <items>
    <item><sku>USB-001</sku><quantity>2</quantity></item>
    <item><sku>MON-002</sku><quantity>1</quantity></item>
  </items>
</order>

HTTP Response Body

HTTP/1.1 201 Created
Content-Type: application/xml

<orderConfirmation>
  <orderId>ORD-2024-9901</orderId>
  <status>accepted</status>
  <estimatedDelivery>2024-03-20</estimatedDelivery>
</orderConfirmation>

Industries That Rely on XML Web Services

IndustryXML Usage
BankingISO 20022 — XML messages for payments and financial transactions
HealthcareHL7 — patient records, prescriptions, lab results
GovernmentXBRL — company financial reporting to regulators
E-commerceUBL — purchase orders, invoices, shipment notices
TravelOpenTravel — flight, hotel, and car rental booking messages

Key Points to Remember

  • XML is the data format for SOAP web services and many REST APIs.
  • WSDL describes a web service's operations, inputs, and outputs in XML.
  • XML web services are platform-independent — Java, Python, .NET all communicate using the same XML messages.
  • Banking, healthcare, and government systems use XML standards for structured data exchange.
  • HTTP carries XML in the request and response body; Content-Type is application/xml.

Leave a Comment

Your email address will not be published. Required fields are marked *