What Is a Schema?
A schema is similar to a WSDL in that both are XML documents. Whereas the WSDL defines the web service language used by computers to converse, the schema defines the data types used in the WSDL.
You do not have to create schemas to use Product Advertising API. Those have already been created. It is helpful, however, to understand schemas so that you can determine the data types returned in responses.
The W3C defines the base data types, which include, for example, int, string, and float. While these data types are useful, they are not very descriptive. For example, defining every occurrence of text in an XML document as being of type string hides the differences between text that is, for example, a paragraph and a note. In such an application where paragraphs and notes are used, a schema would contain an extension of the string base class so that paragraph (<para>) and note (<note>) could be used as tags in XML documents.
Schemas enable you to create your own data types for the purpose of identifying the content in an XML document. All data types that you create must be based on the base data types defined by the W3C. This is the schema namespace defined in the WSDL example.
The data types that can be created are either simple or complex. Complex types can have sub elements and attributes; simple types cannot.
In the WSDL section of this chapter, you saw that complex types are declared as complexType. In the following example, the element, SearchBinSet, is defined as having two child elements, Bin and NarrowBy.
<xs:element name="SearchBinSet"> <xs:complexType> <xs:sequence> <xs:element ref="tns:Bin" minOccurs="0" maxOccurs="unbounded" /> </xs:sequence> <xs:attribute name="NarrowBy" type="xs:string" use="required" /> </xs:complexType> </xs:element>
The NarrowBy attribute is defined in terms of a base type, string. The Bin parameter, however, is not. That means that Bin is defined elsewhere in the schema. Schema syntax, like WSDL syntax, calls for using the keyword "ref" if the element is defined elsewhere in a schema.
The next step in understanding Bin would be to see its definition in the schema. It might be that all of Bin's sub elements are defined by base types. In that case, the research would be over; you would have the full definition of SearchBinSet and it's child elements. If, however, Bin contains more "ref's," you would repeat the search for the child elements until you reached element type definitions that used base types, as shown in the following example.