Working with XML Schemas ©NIITeXtensible Markup Language/Lesson 3/Slide 1 of 36 Objectives In this lesson, you will learn to: * Declare attributes in an.

Slides:



Advertisements
Similar presentations
XML-XSL Introduction SHIJU RAJAN SHIJU RAJAN Outline Brief Overview Brief Overview What is XML? What is XML? Well Formed XML Well Formed XML Tag Name.
Advertisements

What is XML? a meta language that allows you to create and format your own document markups a method for putting structured data into a text file; these.
XML Language Family Detailed Examples Most information contained in these slide comes from: These slides are intended.
Copyright © Open Applications Group, Inc. All rights reserved 1 OAGi XML Schema User Report June 21, Michael.
1 Substitution Groups in XML Schemas Tomer Shiran Winter 2003/4 Semester.
XML Namespaces Andrey Smirnov CSCI 7818 September 21, 2000.
Sunday, June 28, 2015 Abdelali ZAHI : FALL 2003 : XML Schemas XML Schemas Presented By : Abdelali ZAHI Instructor : Dr H.Haddouti.
Unit 4 – XML Schema XML - Level I Basic.
Introduction to XML This material is based heavily on the tutorial by the same name at
Manohar – Why XML is Required Problem: We want to save the data and retrieve it further or to transfer over the network. This.
Working with Namespaces Combining XML Vocabularies in a Compound Document.
WORKING WITH NAMESPACES
XP New Perspectives on XML Tutorial 4 1 XML Schema Tutorial – Carey ISBN Working with Namespaces and Schemas.
Tutorial 3: XML Creating a Valid XML Document. 2 Creating a Valid Document You validate documents to make certain necessary elements are never omitted.
XP New Perspectives on XML Tutorial 3 1 DTD Tutorial – Carey ISBN
Integrating XML with Microsoft SQL Server ©NIITeXtensible Markup Language/Lesson 9/Slide 1 of 31 Objectives In this lesson, you will learn to: * Generate.
Why XML ? Problems with HTML HTML design - HTML is intended for presentation of information as Web pages. - HTML contains a fixed set of markup tags. This.
VICTORIA UNIVERSITY OF WELLINGTON Te Whare Wananga o te Upoko o te Ika a Maui SWEN 432 Advanced Database Design and Implementation XML Schema 1 Lecturer.
XML Schema Vinod Kumar Kayartaya. What is XML Schema?  XML Schema is an XML based alternative to DTD  An XML schema describes the structure of an XML.
1 XML Schemas. 2 Useful Links Schema tutorial links:
Dr. Azeddine Chikh IS446: Internet Software Development.
Neminath Simmachandran
McGraw-Hill/Irwin © 2004 by The McGraw-Hill Companies, Inc. All rights reserved. Schemas Ellen Pearlman Eileen Mullin Programming the Web Using XML.
XML CPSC 315 – Programming Studio Fall 2008 Project 3, Lecture 1.
Using JavaBeans and Custom Tags in JSP Lesson 3B / Slide 1 of 37 J2EE Web Components Pre-assessment Questions 1.The _____________ attribute of a JSP page.
1 © Netskills Quality Internet Training, University of Newcastle Introducing XML © Netskills, Quality Internet Training University.
XML eXtensible Markup Language Part 2.
XP 1 DECLARING A DTD A DTD can be used to: –Ensure all required elements are present in the document –Prevent undefined elements from being used –Enforce.
What is XML?  XML stands for EXtensible Markup Language  XML is a markup language much like HTML  XML was designed to carry data, not to display data.
1 Tutorial 13 Validating Documents with DTDs Working with Document Type Definitions.
Avoid using attributes? Some of the problems using attributes: Attributes cannot contain multiple values (child elements can) Attributes are not easily.
Beginning XML 4th Edition. Chapter 5: XML Schemas.
New Perspectives on XML, 2nd Edition
XML Schema. Why Schema? To define a class of XML documents Serve same purpose as DTD “Instance document" used for XML document conforming to schema.
XP New Perspectives on XML, 2nd Edition Tutorial 2 1 TUTORIAL 2 WORKING WITH NAMESPACES.
XML – Part III. The Element … This type of element either has the element content or the mixed content (child element and data) The attributes of the.
Sheet 1XML Technology in E-Commerce 2001Lecture 2 XML Technology in E-Commerce Lecture 2 Logical and Physical Structure, Validity, DTD, XML Schema.
Advanced Accounting Information Systems Day 31 XML Language Foundation November 6, 2009.
XML Basics A brief introduction to XML in general 1XML Basics.
XML 2nd EDITION Tutorial 4 Working With Schemas. XP Schemas A schema is an XML document that defines the content and structure of one or more XML documents.
1 Tutorial 14 Validating Documents with Schemas Exploring the XML Schema Vocabulary.
Tutorial 13 Validating Documents with Schemas
1 Tutorial 12 Working with Namespaces Combining XML Vocabularies in a Compound Document.
Internet & World Wide Web How to Program, 5/e. © by Pearson Education, Inc. All Rights Reserved.2.
XML Validation II Schemas Robin Burke ECT 360. Outline Namespaces Documents  Data types XML Schemas Elements Attributes Derived data types RELAX NG.
1 Compound Documents: Combining XML Vocabularies.
XSD: XML Schema Language Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.
XML Schema Definition (XSD). Definition of a Schema It is a model for describing the structure and content of data The XML Schema was developed as a content.
Accessing XML Documents Using DOM ©NIITeXtensible Markup Language/Lesson 8/Slide 1 of 23 Objectives In this lesson, you will learn to: * Use XML DOM objects.
Tutorial 2: XML Working with Namespaces. 2 Name Collision This figure shows two documents each with a Name element.
XML Validation II Advanced DTDs + Schemas Robin Burke ECT 360.
 XML derives its strength from a variety of supporting technologies.  Structure and data types: When using XML to exchange data among clients, partners,
Displaying Data with XSLT ©NIITeXtensible Markup Language/Lesson 6/Slide 1 of 45 Objectives In this lesson, you will learn to: * Perform conditional formatting.
Learning XML Basics ©NIITeXtensible Markup Language/Lesson 1/Slide 1 of 40 Objectives In this session, you will learn to: * Identify the limitations of.
Rendering XML Documents ©NIITeXtensible Markup Language/Lesson 5/Slide 1 of 46 Objectives In this session, you will learn to: * Define rendering * Identify.
XML Namespaces In this first lesson XML Namespaces, you will learn to:
1 Extensible Stylesheet Language (XSL) Extensible Stylesheet Language (XSL)
CITA 330 Section 4 XML Schema. XML Schema (XSD) An alternative industry standard for defining XML dialects More expressive than DTD Using XML syntax Promoting.
Web Services: Principles & Technology Slide 3.1 Chapter 3 Brief Overview of XML COMP 4302/6302.
4 Copyright © 2004, Oracle. All rights reserved. Validating XML by Using XML Schema.
Creating Groups of Elements and Attributes in an XML Schema ©NIITeXtensible Markup Language/Lesson 4/Slide 1 of 28 Objectives In this lesson, you will.
Tutorial 03 Working with Schemas 1. Contents The University Hospital Problem Solution 2.
XML Schemas Dr. Awad Khalil Computer Science Department AUC.
In this session, you will learn to:
Document Type Definition
Namespace Review 21-Nov-18.
Namespace Review 29-Dec-18.
New Perspectives on XML
Namespace Review 14-Oct-19.
New Perspectives on XML
Presentation transcript:

Working with XML Schemas ©NIITeXtensible Markup Language/Lesson 3/Slide 1 of 36 Objectives In this lesson, you will learn to: * Declare attributes in an XML schema * Identify the need for XML namespaces * Use the components of one XML schema in another

Working with XML Schemas ©NIITeXtensible Markup Language/Lesson 3/Slide 2 of 36 Problem Statement 3.D.1 * The head office of CyberShoppe sends information about its products to its branch offices. The product details must be stored in a consistent format. Restrictions must be placed on the kind 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. The product details comprise the name of the product, a brief description about it, the price of the product, and the quantity available in stock. The price of the product must always be greater than zero. In addition to these details, you also need to store the category and product ID.

Working with XML Schemas ©NIITeXtensible Markup Language/Lesson 3/Slide 3 of 36 Task List * Identify the elements and attributes required in the XML document. * Identify the method for declaring an attribute in an XML schema. * Identify the mechanism to restrict the values that can be assigned to an attribute. * Declare elements and attributes. * Create an XML document. * Validate the XML document against the schema.

Working with XML Schemas ©NIITeXtensible Markup Language/Lesson 3/Slide 4 of 36 Task 1: Identify the elements and attributes required in the XML document. Result * The required elements are: 3 PRODUCTDATA 3 PRODUCT 3 PRODUCTNAME 3 DESCRIPTION 3 PRICE 3 QUANTITY

Working with XML Schemas ©NIITeXtensible Markup Language/Lesson 3/Slide 5 of 36 Task 1: Identify the…XML document. (Contd.) * The required attributes are: 3 PRODID 3 CATEGORY

Working with XML Schemas ©NIITeXtensible Markup Language/Lesson 3/Slide 6 of 36 Task 2: Identify the method for declaring an attribute in an XML schema. * The attribute Element 3 In XSD, an attribute for a user-defined element is declared using the attribute element. 3 The syntax for declaring an attribute in XSD is given below:

Working with XML Schemas ©NIITeXtensible Markup Language/Lesson 3/Slide 7 of 36 Task 2: Identify the … XML schema. (Contd.) * The attribute Element (Contd.) 3 The attribute element contains attributes that are used to further qualify and restrict the scope and usage of the user-defined attribute. These attributes are discussed below. 3 The name Attribute ä Is used to specify the name of a user-defined attribute. ä Must be used when the schema element is the parent element of the attribute element.

Working with XML Schemas ©NIITeXtensible Markup Language/Lesson 3/Slide 8 of 36 Task 2: Identify the … XML schema. (Contd.) 3 The default Attribute ä Is used to specify a default value for an attribute. 3 The fixed Attribute ä Is used to specify a fixed value for an attribute 3 The ref Attribute ä Is used to reference a user-defined attribute declared in the same or any other XSD document.

Working with XML Schemas ©NIITeXtensible Markup Language/Lesson 3/Slide 9 of 36 Task 2: Identify the … XML schema. (Contd.) 3 The type Attribute ä Takes a value, which specifies the data type of the user-defined attribute. ä Attributes can be associated with both built-in and user-defined simple data types. 3 The use Attribute ä The use attribute specifies the way in which an attribute must be used in an XML document.

Working with XML Schemas ©NIITeXtensible Markup Language/Lesson 3/Slide 10 of 36 Task 2: Identify the … XML schema. (Contd.) ä The values that can be assigned to the use attribute are as follows: ä optional: Specifies that the use of the attribute in the XML document is optional. ä required: Specifies that the use of the attribute is mandatory.

Working with XML Schemas ©NIITeXtensible Markup Language/Lesson 3/Slide 11 of 36 Task 2: Identify the … XML schema. (Contd.) * Global Attributes 3 Global attributes are attributes that are declared outside all element declarations. For such attributes, the schema element is the parent element. 3 After declaring a global attribute, you can reuse this attribute from anywhere within the schema. 3 Global attributes can be associated with both simple and complex data types.

Working with XML Schemas ©NIITeXtensible Markup Language/Lesson 3/Slide 12 of 36 Task 2: Identify the … XML schema. (Contd.) Result * In order to declare the category and ProdID attributes, you should use the attribute element of XSD.

Working with XML Schemas ©NIITeXtensible Markup Language/Lesson 3/Slide 13 of 36 Task 3: Identify the mechanism to restrict the values that can be assigned to an attribute. Result * In order to restrict values that can be assigned to an attribute, you need to declare the attribute and associate it with a user-defined simple data type. * Next, you need to create the simple data type by using the simpleType element of XSD. * Finally, you need to use the restriction element of XSD within the simpleType element in order to restrict the values that can be assigned to the elements or attributes that use the simple data type.

Working with XML Schemas ©NIITeXtensible Markup Language/Lesson 3/Slide 14 of 36 Task 4: Declare elements and attributes. Task 5: Create an XML document. Task 6: Validate the XML document against the schema.

Working with XML Schemas ©NIITeXtensible Markup Language/Lesson 3/Slide 15 of 36 Just a Minute… *In addition to storing the name of the book, first and last names of the author, and price of the book, you also need to store the book ID and the type of cover for each book. The type of cover can be either hard or soft. Declare the elements and attributes required to store book details. The book ID can also be used in different XML documents that store products data. Ensure that the book ID attribute is reusable.

Working with XML Schemas ©NIITeXtensible Markup Language/Lesson 3/Slide 16 of 36 XML Namespaces * Introduction to XML Namespaces 3 A namespace is a method of preventing conflicts between elements having same names. 3 In XML, a namespace is a virtual space that is assigned or recognized by a Uniform Resource Identifier (URI). 3 A URI is a string that uniquely identifies the elements and attributes from different schemas. 3 A namespace URI is not the same as a Web URI. It does not actually point to a resource on the Internet. It is just a unique identifier used to resolve conflicts between elements having same names.

Working with XML Schemas ©NIITeXtensible Markup Language/Lesson 3/Slide 17 of 36 XML Namespaces (Contd.) * Introduction to XML Namespaces (Contd.) 3 You can assign any name or string as a URI. 3 XML allows you to map a prefix to a URI. You can think of a prefix as an alias for a namespace URI.

Working with XML Schemas ©NIITeXtensible Markup Language/Lesson 3/Slide 18 of 36 XML Namespaces (Contd.) * Declaring Namespaces 3 A namespace can be declared in the XSD document by using the xmlns keyword. 3 This keyword is an attribute of the schema element, which is declared at the beginning of the document. 3 The general form of the xmlns keyword is as follows: xmlns:prefix=“URI” 3 There are two kinds of namespace declarations, default and explicit.

Working with XML Schemas ©NIITeXtensible Markup Language/Lesson 3/Slide 19 of 36 XML Namespaces (Contd.) * Default Declaration 3 The default declaration statement enables you to declare a default namespace for a document. 3 In case of a default namespace, you need not specify the prefix.

Working with XML Schemas ©NIITeXtensible Markup Language/Lesson 3/Slide 20 of 36 XML Namespaces (Contd.) * Explicit Declaration 3 In an explicit declaration, the xmlns keyword associates a prefix with a namespace URI, as shown in the following example: : 3 Only those elements and attributes that explicitly use this prefix come under the scope of the specified namespace.

Working with XML Schemas ©NIITeXtensible Markup Language/Lesson 3/Slide 21 of 36 Problem Statement 3.D.2 * The branches of CyberShoppe purchase various products from their suppliers. The details about all these purchase orders are sent to the head office for reporting purposes. To ensure that the data can be accessed, regardless of the hardware and software used at the head office, the branches send data in an XML format. On receiving this data, the head office needs to verify that all branches have specified the required information. It also needs to verify that the data sent by various branches is in a consistent format.

Working with XML Schemas ©NIITeXtensible Markup Language/Lesson 3/Slide 22 of 36 Problem Statement 3.D.2 (Contd.) The purchase order details sent by various branches include the product ID, order ID, date of the purchase order, name and address of the supplier, quantity ordered, and price per unit. The product ID and the order ID are used repeatedly in a number of documents. The product ID begins with P followed by 3 digits. Similarly, the order ID begins with O followed by 3 digits. These restrictions must be specified at a centralized location in such a way that they can be applied across multiple documents.

Working with XML Schemas ©NIITeXtensible Markup Language/Lesson 3/Slide 23 of 36 Task List * Identify the elements and attributes required to store data. * Identify a mechanism for applying restrictions across multiple documents. * Declare reusable data types. * Declare the elements and attributes to be used for storing data. * Create an XML document. * Validate the XML document against the schema.

Working with XML Schemas ©NIITeXtensible Markup Language/Lesson 3/Slide 24 of 36 Task 1: Identify the elements and attributes required to store data. Result * The elements required to store data about purchase orders are: 3 PURCHASEORDER 3 ORDER 3 DATE 3 PRODUCTNAME 3 SUPPLIERNAME 3 ADDRESS 3 QUANTITY 3 PRICEPERQTY

Working with XML Schemas ©NIITeXtensible Markup Language/Lesson 3/Slide 25 of 36 Task 1: Identify the …store data. (Contd.) * The attributes required to store data about purchase orders are: 3 ORDERID 3 PRODID

Working with XML Schemas ©NIITeXtensible Markup Language/Lesson 3/Slide 26 of 36 Task 2: Identify a mechanism for applying restrictions across multiple documents. * The components declared in one schema can be reused by another schema. * This can be done either by using the include or import elements. * The include element 3 The syntax for using the include element is given below:

Working with XML Schemas ©NIITeXtensible Markup Language/Lesson 3/Slide 27 of 36 Task 2: Identify a mechanism…documents. (Contd.) 3 The include element can have multiple occurrences in an XSD document. 3 The schema element is the parent element of the include element. 3 The include element allows reference to any external schema, which is defined in the context of the same target namespace. 3 A target namespace has a reference to a URI to which a schema belongs. 3 The target namespace for a schema is declared using the targetNamespace attribute of the schema element.

Working with XML Schemas ©NIITeXtensible Markup Language/Lesson 3/Slide 28 of 36 Task 2: Identify a mechanism …documents. (Contd.) * The import element 3 The import element performs the same function as the include element. However, the import element allows you to access components from multiple schemas that may belong to different target namespaces. 3 The syntax for using the import element is given below:

Working with XML Schemas ©NIITeXtensible Markup Language/Lesson 3/Slide 29 of 36 Task 2: Identify a mechanism …documents. (Contd.) * The import element (Contd.) 3 The id attribute takes the ID of the element as its value. This ID must be unique for the XSD document. This attribute is optional. 3 The namespace attribute is used to specify a URI. It also specifies the prefix, which is used to associate an element or an attribute with a particular namespace. 3 The schemaLocation attribute is identical to the one used by the include element. The value of this attribute is set to the physical location of the specified schema file.

Working with XML Schemas ©NIITeXtensible Markup Language/Lesson 3/Slide 30 of 36 Task 2: Identify a mechanism …documents. (Contd.) * Result: 3 In the given scenario, you can create reusable data types required for storing product ID and order ID in an XML schema. 3 You can specify the restrictions on these data types. 3 Then, you can use the include or import elements to reference these data types in another schema that contains the declarations for elements and attributes required for storing purchase order data.

Working with XML Schemas ©NIITeXtensible Markup Language/Lesson 3/Slide 31 of 36 Task 3: Declare reusable data types. Task 4: Declare the elements and attributes to be used for storing data. Task 5: Create an XML document. Task 6: Validate the XML document against the schema.

Working with XML Schemas ©NIITeXtensible Markup Language/Lesson 3/Slide 32 of 36 Just a Minute… *The branch offices of CyberShoppe send the details about the sales made by them to the head office. To ensure that the data can be accessed regardless of the hardware and software used at the head office, the branches need to store their data in an XML format. When the head office receives this data, it needs to verify that all branches have specified all required information. It also needs to verify that the data sent by various branches is in a consistent format.

Working with XML Schemas ©NIITeXtensible Markup Language/Lesson 3/Slide 33 of 36 Just a Minute…(Contd.) The sales details sent by various branch offices include the product ID, transaction ID, date of transaction, customer ID, quantity ordered, and price per unit. The product ID, the transaction ID, and the customer ID are used repeatedly in a number of documents. Create reusable data types for storing these details. Also create an XML schema that uses these data types for storing sales details. The product ID should contain the pattern “P[0-9][0-9][0-9]”.

Working with XML Schemas ©NIITeXtensible Markup Language/Lesson 3/Slide 34 of 36 Summary In this lesson you learned that, * The attribute element is used to declare an attribute in the XSD document. * The attribute element has the following attributes: 3 name : Specifies the name of the user-defined attribute. 3 ref : Contains a reference to a global attribute. 3 default : Specifies a default value for an attribute. 3 fixed : Specifies a fixed value for an attribute.

Working with XML Schemas ©NIITeXtensible Markup Language/Lesson 3/Slide 35 of 36 Summary (Contd.) 3 use : Specifies whether the use of the user-defined attribute is mandatory or optional. Also allows you to specify the default value for an attribute.  type : Specifies the data type of the attribute.  The use attribute of the attribute element can take optional or required as its value. *A global attribute is used to declare an attribute that is not associated with any element and that can be reused within a schema. *A namespace is used to avoid naming conflicts between elements having same names.

Working with XML Schemas ©NIITeXtensible Markup Language/Lesson 3/Slide 36 of 36 Summary (Contd.) * The namespace is declared using the xmlns keyword. * You can reference a schema from another schema by using the include element or the import element. * The include element is used to reference a schema in which the target namespace is the same as that of the containing document. * The import element is used to reference a schema in which the target namespace is different from that of the containing schema.