What Is XML?

XML (Extensible Markup Language) is a standard defined by the World Wide Web Consortium (W3C). XML uses tags (identifiers enclosed in brackets, for example, <para>) to label content in text documents. These tags, collectively called the "markup," can be read by humans and computers. XML tags, like SGML tags, encode not only the meaning of the content but also its structure.

XML looks like HTML but XML has nothing to do with the display of the content, which is the central focus of HTML. The following XML tags label the content they enclose as a paragraph.

<para> This is a paragraph.<para>

The <para> tag has nothing to do with the display of the sentence. The tag, for example, does not take attributes such as font, size, or style.

Unlike HTML, there is not a single set of tags used in all XML documents. XML enables designers to create their own set of tags that are appropriate to their business. For example, Product Advertising API encodes its APIs using an XML document called a WSDL. Other companies create their own XML tags to define their APIs. The tags in these two WSDLs most likely would be completely different. The syntax and rules by which the XML elements are defined in the WSDL, however, are the same. Because a web server handles multiple requests that implement multiple WSDLs, each request must specify the WSDL it is using..

XML Syntax

XML tools enforce XML syntax. XML syntax is very similar to HTML syntax, except, like XHTML, the syntax is strictly enforced. The syntax is:

  1. Tags are enclosed within angle brackets, for example,<para>
  2. Opening tags must be paired with closing tags, for example, <para>Sentence<para>
  3. Opening and closing tags must be nested correctly, for example, the following example is well formed
 <note><para>Sentence </para></note> 

The following example is not well formed

 <note><para>Sentence </para></note> 

If these syntax rules are followed, the XML document is said to be well formed. That does not mean, however, that the tags in the XML document are necessarily the ones defined in the associated WSDL. If, for example, the WSDL defines , an XML document that uses would cause an error because "Para" is not defined in the WSDL. When an XML document is well formed and the tags it uses conform to tags defined in the WSDL, the document is said to be valid. Product Advertising API responses always contain valid XML.

XML Structures

Some data in XML documents are one dimensional, for example

<para>Sentence<para> Some data, however, is structured, as shown in the following XML snippet.

<SubTotal>
  <Amount>2998</Amount>
  <CurrencyCode>USD</CurrencyCode>
  <FormattedPrice>$29.98</FormattedPrice>
</SubTotal>

This example shows that the subtotal is comprised of three pieces of data: Amount, CurrencyCode, and FormattedPrice. The example also shows that there can be a hierarchy of tags. In this example, Amount is a child tag of Subtotal. These structures represent arrays of values.

Using XML

So, what do you do with the XML response? The good news is that the Product Advertising API returns a well-defined set of tags for each kind of request. That means that you can use parsing mechanisms to pull out of the XML responses the data that you would like to submit in a second request, or, display on a web page. For instance, in the preceding example, you might parse the XML document to find FormattedPrice so that you could display the $29.98 on a web page that shows an item for sale.

XML is not only used to create requests and responses, it is also used to create a WSDL, which defines the XML tags.