Web Services and SOAP
To understand SOAP in greater detail, you would need additional material describing how SOAP organizes and transports service messages.
From Browser Documents to Program Documents
The web was originally centered on displaying documents in browsers. HTML helped describe how information should appear to people. As it became easier for programs to retrieve and parse documents over HTTP, developers began creating documents intended for other programs to read and process. This change made it possible for separate systems to exchange structured information across the internet.
XML is designed to describe what data means, not how that data should be displayed in a browser.
XML as Hierarchical Data
XML, or eXtensible Markup Language, is a text-based format for encoding structured, hierarchical data using custom tags that describe the meaning of the data.
An XML document is organized as a tree of nested elements. An element has a start tag, content, and an end tag. Elements can contain other elements, so the nesting shows which pieces of data belong together. The outermost element is the root element. Inside it can be repeated elements and child elements that describe increasingly specific information.
A library catalog is a useful XML scenario. A library element can contain multiple book elements, and each book can contain title, author, year, and ISBN elements. The nesting communicates that those details belong to a particular book. A program can parse the document and use the book information in a web application, database, or another system.
Tracing an XML Exchange
What do you think happens?
A library system has created an XML catalog and sends it over HTTP to a web application. What must the receiving application do before it can use the book information?
Reveal answer
Parse the XML and extract the information
The receiving system parses the XML document so it can extract and use the information. XML is intended to describe structured data for programs, rather than to specify how a browser should display that data.
The exchange has four important stages. One system creates an XML document. The document travels over HTTP to another system. The receiving system parses the document. Finally, the receiving system uses the extracted information, such as displaying books, storing them, or sending them onward. The XML document is the vehicle carrying the structured information between the systems.
XML and HTML
| Aspect | XML | HTML |
|---|---|---|
| Primary purpose | Describe the meaning and structure of data | Describe how data should be displayed |
| Tags | Custom tags chosen to describe the data | A predefined set used for web-page structure and display |
| Typical reader | A program that parses and uses the data | A browser displaying a document |
| Strength | Complex, document-style hierarchies | Presenting documents to people in browsers |
XML and HTML can both use tags, but their tags serve different purposes.
The presence of angle-bracket tags does not make XML and HTML interchangeable. Their central difference is what the tags are meant to communicate: XML communicates data meaning, while HTML communicates document display.
XML and JSON Choices
XML and JSON are both used to exchange data across the web, but they are suited to different situations. XML is best suited to document-style data with complex hierarchies. JSON is better suited to simple dictionaries, lists, and lightweight program-to-program communication.
| Question | XML | JSON |
|---|---|---|
| What kind of data is it best suited for? | Document-style data with complex hierarchies | Simple dictionaries and lists |
| How does it describe information? | Custom tags describe meaning | A lightweight structured representation |
| Where is it commonly encountered? | Enterprise systems, configuration files, and web services | Lightweight program-to-program communication |
The choice depends on the shape and purpose of the data exchange.
SOAP in This Concept Hub
SOAP appears in this topic alongside web services, but the supplied material focuses on the XML foundation rather than defining SOAP's message structure or specifying its individual parts. The supported connection is that XML remains important in web services and in program-to-program data exchange. To understand SOAP in greater detail, you would need additional material describing how SOAP organizes and transports service messages.
Mistakes in Format Selection
Common mistake Treating XML as a replacement for HTML display markup
What it looks likeChoosing XML because the document will be shown in a browser
Why it failsXML is intended to describe structured data for programs, while HTML is used to describe how a document should be displayed.
Do this insteadChoose XML when the main need is exchanging or organizing data, and distinguish that purpose from browser presentation.
Common mistake Assuming that custom XML tags are predefined like HTML tags
What it looks likeExpecting every XML document to use one universal tag vocabulary
Why it failsThe extensible part of XML means that developers define tags to describe their own data.
Do this insteadRead the tag names in context and use the document's nesting and names to understand the data.
Common mistake Using XML automatically for every web exchange
What it looks likeSelecting XML for a small, lightweight dictionary or list without considering the data's shape
Why it failsJSON is identified as a better fit for simple dictionaries, lists, and lightweight program-to-program communication.
Do this insteadUse the structure and purpose of the data to guide the choice: complex document-style hierarchies favor XML, while simpler exchanges favor JSON.
Common mistake Thinking that sending XML completes the exchange
What it looks likeStopping after System A sends a document
Why it failsThe receiving system must parse the XML to extract and use the information.
Do this insteadTrace both sides: creation and sending by one system, followed by receiving, parsing, and using by the other.
Check Your Understanding
A company needs to exchange a complex catalog containing groups of products and detailed information about each product. Another team needs to exchange a small list of values between two programs. Which format is the better starting choice for each case, and why?
Hints
- Look at whether the information is document-style and deeply hierarchical.
- Compare that with a simple list intended for lightweight program-to-program communication.
Tracing a Library Catalog
A library system must share book information with a separate web application. The catalog contains multiple books, and each book has a title, author, publication year, and ISBN.
- 1Identify the structure
The catalog is document-style data with a natural hierarchy: a library contains books, and each book contains descriptive details.
- 2Choose a representation
XML is a suitable choice because custom nested elements can describe the catalog and its relationships clearly.
- 3Send the document
The library system creates the XML document and sends it over HTTP to the web application.
- 4Process the document
The web application parses the XML and extracts the book information.
- 5Use the result
The application can use the extracted information to display books, store them, or send the information to another system.
The XML document acts as a self-describing vehicle for moving the library's structured catalog from one system to another.
Key Takeaways
- 1XML is a text-based format for structured, hierarchical data.
- 2Custom XML tags describe the meaning of data, while HTML primarily describes how documents should be displayed.
- 3Nested XML elements form a tree that represents relationships between data items.
- 4Programs can create XML, send it over HTTP, and have another program parse and use it.
- 5XML fits complex document-style data, while JSON fits simple dictionaries, lists, and lightweight program-to-program communication.
- 6A full explanation of SOAP requires additional details beyond the XML and web-service exchange material covered here.
At a glance
- XML describes the meaning and structure of data through custom, nested tags.
- An XML document is a tree whose elements show relationships between pieces of information.
- Web-service exchange can involve one program creating XML, sending it over HTTP, and another program parsing it.
- HTML is mainly for browser display, whereas XML is for structured data representation.
- XML suits complex document-style data; JSON suits simpler dictionaries, lists, and lightweight exchanges.