• No results found

Extensible Markup Language

In document Mastering Web Services Security pdf (Page 57-59)

In order to understand Web Services, the reader must understand XML. Much of what we’ll be discussing in this chapter, and other chapters in this book, is based on XML. You’ll see it in many of our examples.

XML is a derivative of the Standard General Markup Language (SGML) (ISO 1986). SGML is an international standard for defining electronic documents and has existed as an ISO standard since 1986. SGML is a meta document definition language used for describing many document types. It specifies ways to describe portions of a document with identifying tags. Specific document types are defined by a document type defini- tion (DTD). A DTD may have an associated parser, which is software that processes that document type.

HTML, an SGML application, has been well accepted on the Web but regarded as limited because of its fixed set of tags and attributes. What was needed was a way to define other kinds of Internet documents with their own markups, which led to the creation of XML. Work on XML began in 1996, under the auspices of the World Wide Web Consortium (W3C). The XML Special Interest Group, chaired by Jon Bosak of Sun Microsystems, took on the work. It was adopted as a W3C Recommendation in 1998 (W3C 2000).

XML is a specialized version of SGML used to describe electronic documents avail- able over the Internet. Like SGML, XML is a document definition metalanguage. Since XML is a subset of SGML, XML documents are legal SGML documents. However, not all SGML documents are legal XML documents.

XML describes the structure of electronic documents by specifying the tags that identify and delimit portions of documents. Each of these portions is called an element. Elements can be nested. The top-level element is called the root. Elements enclosed by the root are its child elements. Each one of these elements can, in turn, have its own

child elements. In addition, XML provides a way to associate name-value pairs, called attributes, with elements. XML also specifies what constitutes a well-formed document and processing requirements. XML, like SGML, allows for DTDs. But, DTDs are not used with SOAP, which will be discussed later in this chapter. Instead, SOAP uses XML Schemas, so our examples will be based on XML Schemas rather than DTDs.

XML elements begin with a start tag and end with an end tag. Each document type has a set of legal tags. Start tags consist of a label enclosed by a left angle bracket (<) and a right angle bracket (>). The corresponding end tag is the same label as in the start tag prefaced by a slash (/), both enclosed by the left and right angle brackets. For instance, a price element looks like <price>123.45</price>. Unlike HTML, every start tag must be matched by a corresponding end tag.

Start tags may also contain name-value pairs called attributes. Attributes are used to characterize the element between the start and end tags. In our previous example, a currency attribute could be included in the start tag to designate the currency of the price, <price currency=”USdollars”> 123.45</price>. There are several kinds of attrib- utes. Those most commonly encountered are strings. A specific predefined attribute that will be important later in this chapter is ID. The IDattribute associates a name with an element of an XML document.

XML defines a small number of syntax restrictions such as requiring an end tag to follow a start tag. These restrictions enable the use of XML parsers, which must be flex- ible enough to work with any XML-specified document. Any document that follows these restrictions is said to be well formed.

The term XML is used in the literature in several ways. The common uses are:

■■ The metalanguage specified in (W3C 2000). In our examples, this will involve

the use of XML Schemas as well.

■■ An XML specification for an application-specific document type.

■■ A specific document created using the application-specific markup language.

To clarify these uses, let’s consider the case of a developer wishing to implement a purchasing application. This developer wants to describe a purchase order and decides to use XML, the metalanguage, for this purpose. So, the developer uses XML, the meta- language, to define the tags that identify the elements of a purchase order. The devel- oper defines an orderas a sequence of element. Then, she defines tags for the elements. These elements are orderNum, itemDescription, quantity, unitPrice, and aggregatePrice. The developer also defines an attribute called currency, which can be applied to order. If the attribute is used, the purchase order application will associate the currency of order with the price elements. The resulting XML specification is shown below:

<?xml version=”1.0” encoding=”UTF-8”?> <xs:schema targetNamespace=”www.widgets.com” xmlns:xs=”http://www.w3.org/2001/XMLSchema” xmlns=”www.widgets.com” elementFormDefault=”qualified” attributeFormDefault=”unqualified”> <xs:element name=”order”> <xs:complexType> <xs:sequence> <xs:element name=”orderNum”/> Web Services 31

<xs:element name=”itemDescription”/> <xs:element name=”quantity”/> <xs:element name=”unitPrice”/> <xs:element name=”aggregatePrice”/> </xs:sequence> <xs:attribute name=”currency”/> </xs:complexType> </xs:element> </xs:schema>

An instance of a purchase order is an order for five widgets, part number 9876, for $34.23 each. This XML purchase order document is shown below. Note that each name is now a tag. Values associated with each tag are sandwiched between the start tag and its corresponding end tag. We also use the attribute to designate prices in dollars.

<?xml version=”1.0” encoding=”UTF-8”?> <order currency=”USDollars” xmlns=”www.widgets.com” xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:schemaLocation=”www.widgets.com> <orderNum>9876</orderNum> <itemDescription>widgets</itemDescription> <quantity>5</quantity> <unitPrice>34.23</unitPrice> <aggregatePrice>171.15</aggregatePrice> </order>

Supporting Concepts

XML relies on several other concepts to be effective. Two important concepts used within the XML specification are Uniform Resource Identifiers (URIs) and the XML namespace. XML Schemas, a separate W3C Recommendation, is used with XML to provide greater control over data types. In fact, we’ve already been using all three in our examples.

In document Mastering Web Services Security pdf (Page 57-59)