Concepts / Web Services and SOAP

Web Services and SOAP

XML (eXtensible Markup Language) is a text-based format for encoding structured, hierarchical data using custom tags that describe the meaning of the data.

  • Programming

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.

containscontainscontainscontainscontainslibraryroot elementbookone catalog itemtitlebook titleauthorbook authorbookanother catalog itemyearpublication year
What contains what in an XML document, and how do nested custom tags represent relationships between data elements?

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?

  • Display the XML exactly as a browser page
  • Parse the XML and extract the information
  • Replace the custom tags with HTML automatically
Reveal answer

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.

sends XMLtransportsdelivers documentparses and extractsSystem Acreates XMLHTTPcarries documentWeb serviceexchange pointSystem Bparses XMLBook informationextracted and used
How does structured XML data move from one program to another, and where does the web service fit in the exchange?

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

AspectXMLHTML
Primary purposeDescribe the meaning and structure of dataDescribe how data should be displayed
TagsCustom tags chosen to describe the dataA predefined set used for web-page structure and display
Typical readerA program that parses and uses the dataA browser displaying a document
StrengthComplex, document-style hierarchiesPresenting documents to people in browsers
read and processdisplayXMLdescribes data meaningProgramparses dataHTMLdescribes displayBrowserdisplays document
How do XML and HTML differ in what their tags mean and how programs or browsers use the documents?

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.

well suited towell suited toComplex documentnested hierarchyXMLdocument-style dataSimple datadictionary or listJSONlightweight exchange
How do XML and JSON differ when representing structured data and choosing an exchange format?
QuestionXMLJSON
What kind of data is it best suited for?Document-style data with complex hierarchiesSimple dictionaries and lists
How does it describe information?Custom tags describe meaningA lightweight structured representation
Where is it commonly encountered?Enterprise systems, configuration files, and web servicesLightweight program-to-program communication

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

  • Treating XML as a replacement for HTML display markup

    XML is intended to describe structured data for programs, while HTML is used to describe how a document should be displayed.

    Fix: Choose XML when the main need is exchanging or organizing data, and distinguish that purpose from browser presentation.

  • Assuming that custom XML tags are predefined like HTML tags

    The extensible part of XML means that developers define tags to describe their own data.

    Fix: Read the tag names in context and use the document's nesting and names to understand the data.

  • Using XML automatically for every web exchange

    JSON is identified as a better fit for simple dictionaries, lists, and lightweight program-to-program communication.

    Fix: Use the structure and purpose of the data to guide the choice: complex document-style hierarchies favor XML, while simpler exchanges favor JSON.

  • Thinking that sending XML completes the exchange

    The receiving system must parse the XML to extract and use the information.

    Fix: Trace both sides: creation and sending by one system, followed by receiving, parsing, and using by the other.

Check Your Understanding

EASY

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.

Identify the structure: The catalog is document-style data with a natural hierarchy: a library contains books, and each book contains descriptive details.

Choose a representation: XML is a suitable choice because custom nested elements can describe the catalog and its relationships clearly.

Send the document: The library system creates the XML document and sends it over HTTP to the web application.

Process the document: The web application parses the XML and extracts the book information.

Use 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

  1. XML is a text-based format for structured, hierarchical data.
  2. Custom XML tags describe the meaning of data, while HTML primarily describes how documents should be displayed.
  3. Nested XML elements form a tree that represents relationships between data items.
  4. Programs can create XML, send it over HTTP, and have another program parse and use it.
  5. XML fits complex document-style data, while JSON fits simple dictionaries, lists, and lightweight program-to-program communication.
  6. A full explanation of SOAP requires additional details beyond the XML and web-service exchange material covered here.

Key Takeaways

  • 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.