Академический Документы
Профессиональный Документы
Культура Документы
Objectives
Ver. 1.0
Session 2
Slide 1 of 36
An XML schema defines the list of elements and attributes that can be used in an XML document. An XML schema specifies the order in which the elements appear in the XML document, and their data types. Microsoft has developed the XML Schema Definition (XSD) language to define the schema of an XML document.
Ver. 1.0
Session 2
Slide 2 of 36
Ver. 1.0
Session 2
Slide 3 of 36
Ver. 1.0
Session 2
Slide 4 of 36
In an XML schema created using XSD, every element must be associated with a data type. XSD provides the following list of predefined data types:
Primitive Derived Atomic List Union
Ver. 1.0
Session 2
Slide 5 of 36
In an XML schema created using XSD, every element must be associated with a data type. XSD provides the following list of predefined data types:
Primitive Derived Atomic List Union
Do not contain elements or attributes. Contain only values.
Ver. 1.0
Session 2
Slide 6 of 36
In an XML schema created using XSD, every element must be associated with a data type. XSD provides the following list of predefined data types:
Primitive Derived Atomic List Union
Are defined by using other data types called base types. Can be built-in or user-defined.
Ver. 1.0
Session 2
Slide 7 of 36
In an XML schema created using XSD, every element must be associated with a data type. XSD provides the following list of predefined data types:
Primitive Derived Atomic List Union
Ver. 1.0
Session 2
Slide 8 of 36
In an XML schema created using XSD, every element must be associated with a data type. XSD provides the following list of predefined data types:
Primitive Derived Atomic List Union
Are derived data types that contain a set of values of atomic data types. Elements referring to a list data type can contain a value only from that defined set.
Ver. 1.0
Session 2
Slide 9 of 36
In an XML schema created using XSD, every element must be associated with a data type. XSD provides the following list of predefined data types:
Primitive Derived Atomic List Union
Ver. 1.0
Session 2
Slide 10 of 36
There are two types of elements, simple and complex that can be defined in a schema. Simple Element
A simple element does not contain any child elements or attributes. It contains only values, such as numbers, strings, and dates. You can specify restrictions on elements by defining a new simple data type from an existing data type using facet values. You can also associate an element with a simple data type.
Ver. 1.0
Session 2
Slide 11 of 36
Ver. 1.0
Session 2
Slide 12 of 36
Complex Element
A complex element contains other elements, attributes, and mixed content. To declare a complex element, you need to first define a complex data type. After defining the complex data type, you can declare a complex element by associating this data type with the element.
Ver. 1.0
Session 2
Slide 13 of 36
The complexType element is used to declare a new complex data type. The name attribute specifies the name of the new complex data type. The Content model declaration contains the declaration for the elements and attributes that make up the content of the complex type.
Ver. 1.0
Session 2
Slide 14 of 36
Problem Statement:
CyberShoppe, a toy and book store in the United States, sends its product information from the head office to the branch offices. The product details must be stored in a consistent format. Restrictions must be placed on the type of data that can be saved in the data store, in order to ensure uniformity and consistency of information. The product details include the product name, a brief description, product price, and the available quantity on hand. The price of the product must always be greater than zero.
Ver. 1.0
Session 2
Slide 15 of 36
Attributes in an XML schema are declared in the same way as elements. Declaring attributes in an XML schema facilitates the assimilation of information for an XML document. Attribute declarations can be defined in two ways:
Simple type definitions: Facilitates local validation of the attribute information. Global attribute declarations: Enables reuse of attributes.
Ver. 1.0
Session 2
Slide 16 of 36
In XSD, an attribute for a user-defined element is declared using the attribute element.
value="value">
The attribute element contains attributes that are used to further qualify and restrict the scope and usage of the user-defined attribute.
Ver. 1.0
Session 2
Slide 17 of 36
Ver. 1.0
Session 2
Slide 18 of 36
Ver. 1.0
Session 2
Slide 19 of 36
Ver. 1.0
Session 2
Slide 20 of 36
Takes a value that specifies the data type of the user-defined attribute.
Ver. 1.0
Session 2
Slide 21 of 36
Specifies the way in which an attribute can be used in an XML document. Values that can be assigned to the use attribute are optional, default, required, and fixed.
Ver. 1.0
Session 2
Slide 22 of 36
Global attributes are declared outside all element declarations. Global attributes facilitate attribute reusability. Global attributes can be associated with simple and complex data types. Global attributes have the schema element as the parent element.
Ver. 1.0
Session 2
Slide 23 of 36
Ver. 1.0
Session 2
Slide 24 of 36
Problem Statement:
The Marketing Manager at CyberShoppe sends its product information from its head office to the branch offices. The branch offices update this file and send it back to the head office on a routine basis. The product details must be stored in a consistent format at all branches. Restrictions must be placed on the type of data that can be saved in the data store, to ensure uniformity and consistency of information. CyberShoppe sells two categories of products, books and toys. Product details include the product name, a brief description, product price, and the available quantity on hand. The product price must always be greater than zero. In addition to these details, the data store needs to store the category and product ID.
Ver. 1.0
Session 2
Slide 25 of 36
In XML, a namespace is a virtual space that is assigned or recognized by a Uniform Resource Identifier (URI). A namespace is a string that uniquely identifies the elements and attributes from different schemas. A namespace is a unique identifier used to resolve conflicts between elements that have the same names. The following guidelines ensure the uniqueness of a URI:
Using a URI that is controlled by the developer. Using a relative URI.
Ver. 1.0
Session 2
Slide 26 of 36
A namespace can be declared in an XSD document by using the xmlns keyword. The general form of the xmlns keyword is:
xmlns:prefix="URI"
xmlns is the name of the attribute. prefix is an optional namespace.
Ver. 1.0
Session 2
Slide 27 of 36
Harry is creating an XML schema using XSD. To associate each element, he is using a data type that specifies the type of content that an element can hold. Harry wants to use such data types that are defined using base data types. Base data types can either be primitive or derived data types. Which of the following data types should Harry use to accomplish this task?
a. b. c. d. Primitive Union List Derived
Answer:
d. Derived
Ver. 1.0
Session 2
Slide 28 of 36
Ver. 1.0
Session 2
Slide 29 of 36
Answer:
c. <EMPLOYEE empid=e001> <EMPNAME> Alice Peterson<BASICPAY> $2000 </BASICPAY></EMPNAME> </EMPLOYEE>
Ver. 1.0
Session 2
Slide 30 of 36
You have been assigned the task of developing an XML schema file for a new Web application in an organization. The application aims to deliver financial news to its subscribers. Financial news comprises the date, the name of the organization, and the pertinent financial information. What should you use to represent the financial news in the XML schema?
a. b. c. d. Complex type element Simple type element Element Attribute
Answer:
a. Complex type element
Ver. 1.0
Session 2
Slide 31 of 36
Joe wants to specify a user-defined attribute in an XML schema. He wants to use the use attribute in the XML schema, but does not want to set the value for the attribute in his XML document. Which of the following values of the use attribute should Joe use in his XML schema?
a. b. c. d. optional default required fixed
Answer:
a. optional
Ver. 1.0
Session 2
Slide 32 of 36
You have created a global attribute named color. Which of the following attributes of the xsd:attribute element will you use to access color?
a. b. c. d. use name ref type
Answer:
c. ref
Ver. 1.0
Session 2
Slide 33 of 36
The simpleType XSD element allows you to create user-defined simple data types. The complexType XSD element allows you to create complex data types.
Ver. 1.0
Session 2
Slide 34 of 36
The use attribute of the attribute element can take optional, default, fixed, or required as its value.
Ver. 1.0
Session 2
Slide 35 of 36
A global attribute is used to declare an attribute that is not associated with any element and can be reused within a schema. A namespace is used to avoid naming conflicts between elements having the same name. A namespace is declared using the xmlns keyword.
Ver. 1.0
Session 2
Slide 36 of 36