Extensible Markup Language: in This Session, You Will Learn To
Extensible Markup Language: in This Session, You Will Learn To
Objectives
Ver. 1.0
Session 4
Slide 1 of 23
Schemas support a high degree of reusability among other schemas. Reusability among other schemas is achieved by using the include or import elements.
Ver. 1.0
Session 4
Slide 2 of 23
The include element can have multiple occurrences in an XSD document. The schema element is the parent element of the include element. The restriction on the usage of this element is that the containing and contained schema files must belong to the same target namespace.
Session 4
Ver. 1.0
Slide 3 of 23
Ver. 1.0
Session 4
Slide 4 of 23
Problem Statement:
The various products at CyberShoppe are purchased from their suppliers through their branch offices. The purchase order details are sent to the head office to generate reports. To ensure that the data can be accessed across all hardware and software used at the head office, the branch offices send data in an XML format. On receiving this data, the head office needs to verify that all branches have specified the required information in a consistent format. The purchase order details sent by the branch offices include the product ID, order ID, date of the purchase order, name and address of the supplier, quantity ordered, and price per unit.
Ver. 1.0
Session 4
Slide 5 of 23
Ver. 1.0
Session 4
Slide 6 of 23
Ver. 1.0
Session 4
Slide 7 of 23
An XML schema combines related elements and attributes into groups. Creating grouped elements and attributes facilitates the following tasks:
Create a reusable group of elements and attributes. Select a single element from a group. Specify the sequence of elements.
XSD provides the following elements to group user-defined elements and attributes:
sequence group choice all attributeGroup
Ver. 1.0
Session 4
Slide 8 of 23
Ver. 1.0
Session 4
Slide 9 of 23
A set of elements can be grouped together by a common name in an XML schema, and incorporated into a complex data type. The syntax for declaring a group element is:
<group maxOccurs="nonNegativeInteg er | unbounded minOccurs="nonNegativeInteg er" name="NCName" ref="QName"> </group>
Specifies the maximum number of times a group can occur in the XML document. Specifies the minimum number of times a group can occur in the XML document. Assigns a name for the group element. Refers to a group in a complex type element
Ver. 1.0
Session 4
Slide 10 of 23
In XSD, a single option can be selected from multiple options using the choice element. The choice element allows only one of the elements contained in the group to be present within the parent element. The syntax for declaring a choice element is:
<choice id="ID" maxOccurs="nonNegativeInteger|unbounded" minOccurs="nonNegativeInteger"> </choice>
Ver. 1.0
Session 4
Slide 11 of 23
Ver. 1.0
Session 4
Slide 12 of 23
Ver. 1.0
Session 4
Slide 13 of 23
Problem Statement:
The customer details of CyberShoppe need to be stored in a central repository. To enable this, the computerized data needs to be collated from the branch offices and maintained at a central location. This data has to be made available to various sections, such as the Accounts and the Sales sections of various branches, irrespective of the hardware and software platforms used. After collating the customer data, the head office needs to verify that the complete information has been made available and is stored in a consistent format. Customer data includes the customer ID, first name, last name, and contact information, such as the address and phone number. A customer may provide residential or official contact information.
Ver. 1.0
Session 4
Slide 14 of 23
Which element enables the incorporation of data into a complex data type?
a. b. c. d. sequence group all attributeGroup
Answer:
b. group
Ver. 1.0
Session 4
Slide 15 of 23
Consider the following statements: Statement A: You can group a set of elements by a common name and incorporate it into a complex data type by using the group element. Statement B: You can reuse a group of elements declared earlier by using the ref attribute of the group element.
Ver. 1.0
Session 4
Slide 16 of 23
Answer:
c. Both, Statement A and Statement B, are True.
Ver. 1.0
Session 4
Slide 17 of 23
Consider the following statements: Statement A: The xsd:choice element allows only one of the elements contained in the group to be present within the parent element. Statement B: You can set the value of the maxOccurs attribute of the xsd:choice element to specify the maximum number of times the group can occur within the parent element.
Ver. 1.0
Session 4
Slide 18 of 23
Answer:
c. Both, Statement A and Statement B, are True.
Ver. 1.0
Session 4
Slide 19 of 23
Answer:
c. <xsd:attribute name=baseprice default=200 type=xsd:integer>
Ver. 1.0
Session 4
Slide 20 of 23
Answer:
d. After declaring a global attribute, you can reuse it anywhere within the schema.
Ver. 1.0
Session 4
Slide 21 of 23
Ver. 1.0
Session 4
Slide 22 of 23
Ver. 1.0
Session 4
Slide 23 of 23