SlideShare uma empresa Scribd logo
1 de 36
Working with XML Schemas


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




©NIIT                    eXtensible Markup Language/Lesson 3/Slide 1 of 36
Working with XML Schemas


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.


©NIIT                  eXtensible Markup Language/Lesson 3/Slide 2 of 36
Working with XML Schemas


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.


©NIIT                  eXtensible Markup Language/Lesson 3/Slide 3 of 36
Working with XML Schemas


Task 1: Identify the elements and attributes
  required in the XML document.
Result
 The required elements are:
     PRODUCTDATA
     PRODUCT
     PRODUCTNAME
     DESCRIPTION
     PRICE
     QUANTITY

©NIIT                eXtensible Markup Language/Lesson 3/Slide 4 of 36
Working with XML Schemas


Task 1: Identify the…XML document. (Contd.)
 The required attributes are:
     PRODID
     CATEGORY




©NIIT                  eXtensible Markup Language/Lesson 3/Slide 5 of 36
Working with XML Schemas


Task 2: Identify the method for declaring an
  attribute in an XML schema.
 The attribute Element
     In XSD, an attribute for a user-defined element is
      declared using the attribute element.
     The syntax for declaring an attribute in XSD is
      given below:
        attribute name=attributename
        ref=attributename type=datatypename
        use=value value=value /attribute




©NIIT                   eXtensible Markup Language/Lesson 3/Slide 6 of 36
Working with XML Schemas


Task 2: Identify the …XML schema. (Contd.)
 The attribute Element (Contd.)
     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.
     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.


©NIIT                   eXtensible Markup Language/Lesson 3/Slide 7 of 36
Working with XML Schemas


Task 2: Identify the …XML schema. (Contd.)
 The attribute Element (Contd.)
     The ref Attribute
        ® Isused to reference a user-defined attribute
          declared in the same or any other XSD
          document.
     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.

©NIIT                   eXtensible Markup Language/Lesson 3/Slide 8 of 36
Working with XML Schemas

Task 2: Identify the …XML schema. (Contd.)
 The attribute Element (Contd.)
     The use Attribute
        ® The  use attribute specifies the way in which an
         attribute must be used in an XML document.
        ® 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.
          ® default: Specifies a default value for an
            attribute. You must use the value attribute of
            the attribute element if you set the value
            of the use attribute to default.
©NIIT                   eXtensible Markup Language/Lesson 3/Slide 9 of 36
Working with XML Schemas


Task 2: Identify the …XML schema. (Contd.)
        ® required:  Specifies that the use of the
          attribute is mandatory.
        ® fixed:Specifies that the attribute has a fixed
          value that cannot be changed in the XML
          document.




©NIIT                 eXtensible Markup Language/Lesson 3/Slide 10 of 36
Working with XML Schemas


Task 2: Identify the …XML schema. (Contd.)
 Global Attributes
     Global attributes are attributes that are declared
      outside all element declarations. For such
      attributes, the schema element is the parent
      element.
     After declaring a global attribute, you can reuse
      this attribute from anywhere within the schema.
     Global attributes can be associated with both
      simple and complex data types.




©NIIT                  eXtensible Markup Language/Lesson 3/Slide 11 of 36
Working with XML Schemas


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.




©NIIT                 eXtensible Markup Language/Lesson 3/Slide 12 of 36
Working with XML Schemas


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.


©NIIT                 eXtensible Markup Language/Lesson 3/Slide 13 of 36
Working with XML Schemas


Task 4: Declare elements and attributes.


Task 5: Create an XML document.


Task 6: Validate the XML document against the
  schema.




©NIIT              eXtensible Markup Language/Lesson 3/Slide 14 of 36
Working with XML Schemas


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.




©NIIT                 eXtensible Markup Language/Lesson 3/Slide 15 of 36
Working with XML Schemas

XML Namespaces
 Introduction to XML Namespaces
     A namespace is a method of preventing conflicts
      between elements having same names.
     In XML, a namespace is a virtual space that is
      assigned or recognized by a Uniform Resource
      Identifier (URI).
     A URI is a string that uniquely identifies the
      elements and attributes from different schemas.
     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.

©NIIT                   eXtensible Markup Language/Lesson 3/Slide 16 of 36
Working with XML Schemas


XML Namespaces (Contd.)
 Introduction to XML Namespaces (Contd.)
     You can assign any name or string as a URI.
     XML allows you to map a prefix to a URI. You can
      think of a prefix as an alias for a namespace URI.




©NIIT                 eXtensible Markup Language/Lesson 3/Slide 17 of 36
Working with XML Schemas

XML Namespaces (Contd.)
 Declaring Namespaces
     A namespace can be declared in the XSD
      document by using the xmlns keyword.
     This keyword is an attribute of the schema
      element, which is declared at the beginning of the
      document.
     The general form of the xmlns keyword is as
      follows:
        xmlns:prefix=“URI”
     There are two kinds of namespace declarations,
      default and explicit.

©NIIT                  eXtensible Markup Language/Lesson 3/Slide 18 of 36
Working with XML Schemas


XML Namespaces (Contd.)
 Default Declaration
    The default declaration statement enables you to declare
     a default namespace for a document.
    In case of a default namespace, you need not specify
     the prefix.




   ©NIIT                eXtensible Markup Language/Lesson 3/Slide 19 of 36
Working with XML Schemas


XML Namespaces (Contd.)
 Explicit Declaration
    In an explicit declaration, the xmlns keyword associates a
     prefix with a namespace URI, as shown in the following
     example:
   xsd:schema
     xmlns:xsd=“http://www.w3.org/2001/XMLSchem
     a”
      :
      /xsd:schema
    Only those elements and attributes that explicitly use this
     prefix come under the scope of the specified namespace.
   ©NIIT                 eXtensible Markup Language/Lesson 3/Slide 20 of 36
Working with XML Schemas


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.



©NIIT                 eXtensible Markup Language/Lesson 3/Slide 21 of 36
Working with XML Schemas


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.




©NIIT                eXtensible Markup Language/Lesson 3/Slide 22 of 36
Working with XML Schemas


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.


©NIIT                 eXtensible Markup Language/Lesson 3/Slide 23 of 36
Working with XML Schemas

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


Task 1: Identify the …store data. (Contd.)
 The attributes required to store data about
  purchase orders are:
    ORDERID
     PRODID




©NIIT               eXtensible Markup Language/Lesson 3/Slide 25 of 36
Working with XML Schemas


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
     The syntax for using the include element is given
      below:
        include id=ID schemaLocation=filename /



©NIIT                   eXtensible Markup Language/Lesson 3/Slide 26 of 36
Working with XML Schemas


Task 2: Identify a mechanism…documents.
  (Contd.)
     The include element can have multiple
      occurrences in an XSD document.
     The schema element is the parent element of the
      include element.
     The include element allows reference to any
      external schema, which is defined in the context of
      the same target namespace.
     A target namespace has a reference to a URI to
      which a schema belongs.
     The target namespace for a schema is declared
      using the targetNamespace attribute of the
      schema element.

©NIIT                 eXtensible Markup Language/Lesson 3/Slide 27 of 36
Working with XML Schemas


Task 2: Identify a mechanism …documents.
  (Contd.)
 The import element
     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.
     The syntax for using the import element is given
      below:
        import id=ID namespace=namespace
        schemaLocation=filename /

©NIIT                 eXtensible Markup Language/Lesson 3/Slide 28 of 36
Working with XML Schemas

Task 2: Identify a mechanism …documents.
  (Contd.)
 The import element (Contd.)
     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.
     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.
     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.
©NIIT                  eXtensible Markup Language/Lesson 3/Slide 29 of 36
Working with XML Schemas

Task 2: Identify a mechanism …documents.
  (Contd.)
 Result:
     In the given scenario, you can create reusable
      data types required for storing product ID and
      order ID in an XML schema.
     You can specify the restrictions on these data
      types.
     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.


©NIIT                 eXtensible Markup Language/Lesson 3/Slide 30 of 36
Working with XML Schemas


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.


©NIIT              eXtensible Markup Language/Lesson 3/Slide 31 of 36
Working with XML Schemas


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.




©NIIT                 eXtensible Markup Language/Lesson 3/Slide 32 of 36
Working with XML Schemas


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]”.




©NIIT                 eXtensible Markup Language/Lesson 3/Slide 33 of 36
Working with XML Schemas


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:
     name: Specifies the name of the user-defined
      attribute.
     ref: Contains a reference to a global attribute.
     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.

©NIIT                  eXtensible Markup Language/Lesson 3/Slide 34 of 36
Working with XML Schemas


Summary (Contd.)
     type: Specifies the data type of the attribute.
     value: Specifies the default or fixed value for a
      user-defined attribute.
 The use attribute of the attribute element can take
  optional, default, fixed, 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.


©NIIT                  eXtensible Markup Language/Lesson 3/Slide 35 of 36
Working with XML Schemas


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.


©NIIT                 eXtensible Markup Language/Lesson 3/Slide 36 of 36

Mais conteúdo relacionado

Mais procurados

Module 5 oodb systems semantic db systems
Module 5 oodb systems  semantic db systemsModule 5 oodb systems  semantic db systems
Module 5 oodb systems semantic db systems
Taher Barodawala
 
08. Object Oriented Database in DBMS
08. Object Oriented Database in DBMS08. Object Oriented Database in DBMS
08. Object Oriented Database in DBMS
koolkampus
 
Ch 12 O O D B Dvlpt
Ch 12  O O  D B  DvlptCh 12  O O  D B  Dvlpt
Ch 12 O O D B Dvlpt
guest8fdbdd
 
9. Object Relational Databases in DBMS
9. Object Relational Databases in DBMS9. Object Relational Databases in DBMS
9. Object Relational Databases in DBMS
koolkampus
 

Mais procurados (20)

Object oriented data model
Object oriented data modelObject oriented data model
Object oriented data model
 
Object database standards, languages and design
Object database standards, languages and designObject database standards, languages and design
Object database standards, languages and design
 
Oodbms ch 20
Oodbms ch 20Oodbms ch 20
Oodbms ch 20
 
Object Oriented Dbms
Object Oriented DbmsObject Oriented Dbms
Object Oriented Dbms
 
Module 5 oodb systems semantic db systems
Module 5 oodb systems  semantic db systemsModule 5 oodb systems  semantic db systems
Module 5 oodb systems semantic db systems
 
Chapt 1 odbms
Chapt 1 odbmsChapt 1 odbms
Chapt 1 odbms
 
Database Design and Normalization Techniques
Database Design and Normalization TechniquesDatabase Design and Normalization Techniques
Database Design and Normalization Techniques
 
Object modeling
Object modelingObject modeling
Object modeling
 
Object oriented database
Object oriented databaseObject oriented database
Object oriented database
 
Islamic University Previous Year Question Solution 2018 (ADBMS)
Islamic University Previous Year Question Solution 2018 (ADBMS)Islamic University Previous Year Question Solution 2018 (ADBMS)
Islamic University Previous Year Question Solution 2018 (ADBMS)
 
08. Object Oriented Database in DBMS
08. Object Oriented Database in DBMS08. Object Oriented Database in DBMS
08. Object Oriented Database in DBMS
 
12 SQL
12 SQL12 SQL
12 SQL
 
Object & classes
Object & classes Object & classes
Object & classes
 
Dbms important questions and answers
Dbms important questions and answersDbms important questions and answers
Dbms important questions and answers
 
Ch 12 O O D B Dvlpt
Ch 12  O O  D B  DvlptCh 12  O O  D B  Dvlpt
Ch 12 O O D B Dvlpt
 
Introduction to Data Science With R Notes
Introduction to Data Science With R NotesIntroduction to Data Science With R Notes
Introduction to Data Science With R Notes
 
ch6
ch6ch6
ch6
 
Overview of Object-Oriented Concepts Characteristics by vikas jagtap
Overview of Object-Oriented Concepts Characteristics by vikas jagtapOverview of Object-Oriented Concepts Characteristics by vikas jagtap
Overview of Object-Oriented Concepts Characteristics by vikas jagtap
 
03 x files
03 x files03 x files
03 x files
 
9. Object Relational Databases in DBMS
9. Object Relational Databases in DBMS9. Object Relational Databases in DBMS
9. Object Relational Databases in DBMS
 

Destaque

SmartRecruiters-MakingTheRightHire
SmartRecruiters-MakingTheRightHireSmartRecruiters-MakingTheRightHire
SmartRecruiters-MakingTheRightHire
Natalia Baryshnikova
 
Informe ampliacion plazo (supervisión)
Informe ampliacion plazo  (supervisión)Informe ampliacion plazo  (supervisión)
Informe ampliacion plazo (supervisión)
ELIASTRIGO
 
Распределенные системы в Одноклассниках / Олег Анастасьев (Одноклассники)
Распределенные системы в Одноклассниках / Олег Анастасьев (Одноклассники)Распределенные системы в Одноклассниках / Олег Анастасьев (Одноклассники)
Распределенные системы в Одноклассниках / Олег Анастасьев (Одноклассники)
Ontico
 
noBackend, или Как выжить в эпоху толстеющих клиентов / Самохвалов Николай
noBackend, или Как выжить в эпоху толстеющих клиентов / Самохвалов НиколайnoBackend, или Как выжить в эпоху толстеющих клиентов / Самохвалов Николай
noBackend, или Как выжить в эпоху толстеющих клиентов / Самохвалов Николай
Ontico
 
Воспитать в себе обезьяну. О том, как все успеть, не превращаясь в биоробота ...
Воспитать в себе обезьяну. О том, как все успеть, не превращаясь в биоробота ...Воспитать в себе обезьяну. О том, как все успеть, не превращаясь в биоробота ...
Воспитать в себе обезьяну. О том, как все успеть, не превращаясь в биоробота ...
Ontico
 

Destaque (20)

SmartRecruiters-MakingTheRightHire
SmartRecruiters-MakingTheRightHireSmartRecruiters-MakingTheRightHire
SmartRecruiters-MakingTheRightHire
 
políticas ambientales
políticas ambientales políticas ambientales
políticas ambientales
 
amithcmcv
amithcmcvamithcmcv
amithcmcv
 
De cuong ky nang quan ly thoi gian va to chuc cong viec lai the luyen
De cuong   ky nang quan ly thoi gian va to chuc cong viec lai the luyenDe cuong   ky nang quan ly thoi gian va to chuc cong viec lai the luyen
De cuong ky nang quan ly thoi gian va to chuc cong viec lai the luyen
 
MRMLOGIQ Elevator Pitch
MRMLOGIQ  Elevator PitchMRMLOGIQ  Elevator Pitch
MRMLOGIQ Elevator Pitch
 
Cati
CatiCati
Cati
 
Introducción a-project-damian
Introducción a-project-damianIntroducción a-project-damian
Introducción a-project-damian
 
De cuong ky nang thuyet trinh trong kinh doanh lai the luyen
De cuong ky nang thuyet trinh trong kinh doanh lai the luyenDe cuong ky nang thuyet trinh trong kinh doanh lai the luyen
De cuong ky nang thuyet trinh trong kinh doanh lai the luyen
 
Informe ampliacion plazo (supervisión)
Informe ampliacion plazo  (supervisión)Informe ampliacion plazo  (supervisión)
Informe ampliacion plazo (supervisión)
 
68564832 pembangunan-pedesaan
68564832 pembangunan-pedesaan68564832 pembangunan-pedesaan
68564832 pembangunan-pedesaan
 
Chernobyl: gran catástrofe nuclear
Chernobyl: gran catástrofe nuclearChernobyl: gran catástrofe nuclear
Chernobyl: gran catástrofe nuclear
 
Java Script Introduction
Java Script IntroductionJava Script Introduction
Java Script Introduction
 
Sustainable housing project propsal
Sustainable  housing   project propsalSustainable  housing   project propsal
Sustainable housing project propsal
 
De cuong ky nang tu duy sang tao clc_lai the luyen
De cuong ky nang tu duy sang tao clc_lai the luyenDe cuong ky nang tu duy sang tao clc_lai the luyen
De cuong ky nang tu duy sang tao clc_lai the luyen
 
Capital city satisfaction survey report 2014.I
Capital city satisfaction survey report 2014.ICapital city satisfaction survey report 2014.I
Capital city satisfaction survey report 2014.I
 
Распределенные системы в Одноклассниках / Олег Анастасьев (Одноклассники)
Распределенные системы в Одноклассниках / Олег Анастасьев (Одноклассники)Распределенные системы в Одноклассниках / Олег Анастасьев (Одноклассники)
Распределенные системы в Одноклассниках / Олег Анастасьев (Одноклассники)
 
noBackend, или Как выжить в эпоху толстеющих клиентов / Самохвалов Николай
noBackend, или Как выжить в эпоху толстеющих клиентов / Самохвалов НиколайnoBackend, или Как выжить в эпоху толстеющих клиентов / Самохвалов Николай
noBackend, или Как выжить в эпоху толстеющих клиентов / Самохвалов Николай
 
Воспитать в себе обезьяну. О том, как все успеть, не превращаясь в биоробота ...
Воспитать в себе обезьяну. О том, как все успеть, не превращаясь в биоробота ...Воспитать в себе обезьяну. О том, как все успеть, не превращаясь в биоробота ...
Воспитать в себе обезьяну. О том, как все успеть, не превращаясь в биоробота ...
 
PKS Angel Funding
PKS Angel FundingPKS Angel Funding
PKS Angel Funding
 
TargetSummit Moscow 2016 | Workshop on RTB media buying, Andrey Shatrov
TargetSummit Moscow 2016 | Workshop on RTB media buying, Andrey ShatrovTargetSummit Moscow 2016 | Workshop on RTB media buying, Andrey Shatrov
TargetSummit Moscow 2016 | Workshop on RTB media buying, Andrey Shatrov
 

Semelhante a 02 sm3 xml_xp_03 (20)

04 sm3 xml_xp_08
04 sm3 xml_xp_0804 sm3 xml_xp_08
04 sm3 xml_xp_08
 
01 sm3 xml_xp_02
01 sm3 xml_xp_0201 sm3 xml_xp_02
01 sm3 xml_xp_02
 
Web Technologies Unit 2 Print.pdf
Web Technologies Unit 2 Print.pdfWeb Technologies Unit 2 Print.pdf
Web Technologies Unit 2 Print.pdf
 
XML
XMLXML
XML
 
Xml session04
Xml session04Xml session04
Xml session04
 
Artefactos biz talk 2006
Artefactos biz talk 2006Artefactos biz talk 2006
Artefactos biz talk 2006
 
XML Schema.pptx
XML Schema.pptxXML Schema.pptx
XML Schema.pptx
 
Tp2
Tp2Tp2
Tp2
 
XML
XMLXML
XML
 
Applied xml programming for microsoft
Applied xml programming for microsoftApplied xml programming for microsoft
Applied xml programming for microsoft
 
02 xml schema
02 xml schema02 xml schema
02 xml schema
 
Xsd examples
Xsd examplesXsd examples
Xsd examples
 
ActionScript 3.0 Fundamentals
ActionScript 3.0 FundamentalsActionScript 3.0 Fundamentals
ActionScript 3.0 Fundamentals
 
Unit 5 xml (1)
Unit 5   xml (1)Unit 5   xml (1)
Unit 5 xml (1)
 
Session 5
Session 5Session 5
Session 5
 
Oracle soa xml faq
Oracle soa xml faqOracle soa xml faq
Oracle soa xml faq
 
XML Schemas
XML SchemasXML Schemas
XML Schemas
 
Ado.net session11
Ado.net session11Ado.net session11
Ado.net session11
 
Xml and DTD's
Xml and DTD'sXml and DTD's
Xml and DTD's
 
XML-Unit 1.ppt
XML-Unit 1.pptXML-Unit 1.ppt
XML-Unit 1.ppt
 

Mais de Niit Care (20)

Ajs 1 b
Ajs 1 bAjs 1 b
Ajs 1 b
 
Ajs 4 b
Ajs 4 bAjs 4 b
Ajs 4 b
 
Ajs 4 a
Ajs 4 aAjs 4 a
Ajs 4 a
 
Ajs 4 c
Ajs 4 cAjs 4 c
Ajs 4 c
 
Ajs 3 b
Ajs 3 bAjs 3 b
Ajs 3 b
 
Ajs 3 a
Ajs 3 aAjs 3 a
Ajs 3 a
 
Ajs 3 c
Ajs 3 cAjs 3 c
Ajs 3 c
 
Ajs 2 b
Ajs 2 bAjs 2 b
Ajs 2 b
 
Ajs 2 a
Ajs 2 aAjs 2 a
Ajs 2 a
 
Ajs 2 c
Ajs 2 cAjs 2 c
Ajs 2 c
 
Ajs 1 a
Ajs 1 aAjs 1 a
Ajs 1 a
 
Ajs 1 c
Ajs 1 cAjs 1 c
Ajs 1 c
 
Dacj 4 2-c
Dacj 4 2-cDacj 4 2-c
Dacj 4 2-c
 
Dacj 4 2-b
Dacj 4 2-bDacj 4 2-b
Dacj 4 2-b
 
Dacj 4 2-a
Dacj 4 2-aDacj 4 2-a
Dacj 4 2-a
 
Dacj 4 1-c
Dacj 4 1-cDacj 4 1-c
Dacj 4 1-c
 
Dacj 4 1-b
Dacj 4 1-bDacj 4 1-b
Dacj 4 1-b
 
Dacj 4 1-a
Dacj 4 1-aDacj 4 1-a
Dacj 4 1-a
 
Dacj 1-2 b
Dacj 1-2 bDacj 1-2 b
Dacj 1-2 b
 
Dacj 1-3 c
Dacj 1-3 cDacj 1-3 c
Dacj 1-3 c
 

Último

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Último (20)

Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 

02 sm3 xml_xp_03

  • 1. Working with XML Schemas 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 ©NIIT eXtensible Markup Language/Lesson 3/Slide 1 of 36
  • 2. Working with XML Schemas 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. ©NIIT eXtensible Markup Language/Lesson 3/Slide 2 of 36
  • 3. Working with XML Schemas 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. ©NIIT eXtensible Markup Language/Lesson 3/Slide 3 of 36
  • 4. Working with XML Schemas Task 1: Identify the elements and attributes required in the XML document. Result The required elements are: PRODUCTDATA PRODUCT PRODUCTNAME DESCRIPTION PRICE QUANTITY ©NIIT eXtensible Markup Language/Lesson 3/Slide 4 of 36
  • 5. Working with XML Schemas Task 1: Identify the…XML document. (Contd.) The required attributes are: PRODID CATEGORY ©NIIT eXtensible Markup Language/Lesson 3/Slide 5 of 36
  • 6. Working with XML Schemas Task 2: Identify the method for declaring an attribute in an XML schema. The attribute Element In XSD, an attribute for a user-defined element is declared using the attribute element. The syntax for declaring an attribute in XSD is given below: attribute name=attributename ref=attributename type=datatypename use=value value=value /attribute ©NIIT eXtensible Markup Language/Lesson 3/Slide 6 of 36
  • 7. Working with XML Schemas Task 2: Identify the …XML schema. (Contd.) The attribute Element (Contd.) 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. 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. ©NIIT eXtensible Markup Language/Lesson 3/Slide 7 of 36
  • 8. Working with XML Schemas Task 2: Identify the …XML schema. (Contd.) The attribute Element (Contd.) The ref Attribute ® Isused to reference a user-defined attribute declared in the same or any other XSD document. 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. ©NIIT eXtensible Markup Language/Lesson 3/Slide 8 of 36
  • 9. Working with XML Schemas Task 2: Identify the …XML schema. (Contd.) The attribute Element (Contd.) The use Attribute ® The use attribute specifies the way in which an attribute must be used in an XML document. ® 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. ® default: Specifies a default value for an attribute. You must use the value attribute of the attribute element if you set the value of the use attribute to default. ©NIIT eXtensible Markup Language/Lesson 3/Slide 9 of 36
  • 10. Working with XML Schemas Task 2: Identify the …XML schema. (Contd.) ® required: Specifies that the use of the attribute is mandatory. ® fixed:Specifies that the attribute has a fixed value that cannot be changed in the XML document. ©NIIT eXtensible Markup Language/Lesson 3/Slide 10 of 36
  • 11. Working with XML Schemas Task 2: Identify the …XML schema. (Contd.) Global Attributes Global attributes are attributes that are declared outside all element declarations. For such attributes, the schema element is the parent element. After declaring a global attribute, you can reuse this attribute from anywhere within the schema. Global attributes can be associated with both simple and complex data types. ©NIIT eXtensible Markup Language/Lesson 3/Slide 11 of 36
  • 12. Working with XML Schemas 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. ©NIIT eXtensible Markup Language/Lesson 3/Slide 12 of 36
  • 13. Working with XML Schemas 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. ©NIIT eXtensible Markup Language/Lesson 3/Slide 13 of 36
  • 14. Working with XML Schemas Task 4: Declare elements and attributes. Task 5: Create an XML document. Task 6: Validate the XML document against the schema. ©NIIT eXtensible Markup Language/Lesson 3/Slide 14 of 36
  • 15. Working with XML Schemas 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. ©NIIT eXtensible Markup Language/Lesson 3/Slide 15 of 36
  • 16. Working with XML Schemas XML Namespaces Introduction to XML Namespaces A namespace is a method of preventing conflicts between elements having same names. In XML, a namespace is a virtual space that is assigned or recognized by a Uniform Resource Identifier (URI). A URI is a string that uniquely identifies the elements and attributes from different schemas. 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. ©NIIT eXtensible Markup Language/Lesson 3/Slide 16 of 36
  • 17. Working with XML Schemas XML Namespaces (Contd.) Introduction to XML Namespaces (Contd.) You can assign any name or string as a URI. XML allows you to map a prefix to a URI. You can think of a prefix as an alias for a namespace URI. ©NIIT eXtensible Markup Language/Lesson 3/Slide 17 of 36
  • 18. Working with XML Schemas XML Namespaces (Contd.) Declaring Namespaces A namespace can be declared in the XSD document by using the xmlns keyword. This keyword is an attribute of the schema element, which is declared at the beginning of the document. The general form of the xmlns keyword is as follows: xmlns:prefix=“URI” There are two kinds of namespace declarations, default and explicit. ©NIIT eXtensible Markup Language/Lesson 3/Slide 18 of 36
  • 19. Working with XML Schemas XML Namespaces (Contd.) Default Declaration The default declaration statement enables you to declare a default namespace for a document. In case of a default namespace, you need not specify the prefix. ©NIIT eXtensible Markup Language/Lesson 3/Slide 19 of 36
  • 20. Working with XML Schemas XML Namespaces (Contd.) Explicit Declaration In an explicit declaration, the xmlns keyword associates a prefix with a namespace URI, as shown in the following example: xsd:schema xmlns:xsd=“http://www.w3.org/2001/XMLSchem a” : /xsd:schema Only those elements and attributes that explicitly use this prefix come under the scope of the specified namespace. ©NIIT eXtensible Markup Language/Lesson 3/Slide 20 of 36
  • 21. Working with XML Schemas 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. ©NIIT eXtensible Markup Language/Lesson 3/Slide 21 of 36
  • 22. Working with XML Schemas 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. ©NIIT eXtensible Markup Language/Lesson 3/Slide 22 of 36
  • 23. Working with XML Schemas 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. ©NIIT eXtensible Markup Language/Lesson 3/Slide 23 of 36
  • 24. Working with XML Schemas Task 1: Identify the elements and attributes required to store data. Result The elements required to store data about purchase orders are: PURCHASEORDER ORDER DATE PRODUCTNAME SUPPLIERNAME ADDRESS QUANTITY PRICEPERQTY ©NIIT eXtensible Markup Language/Lesson 3/Slide 24 of 36
  • 25. Working with XML Schemas Task 1: Identify the …store data. (Contd.) The attributes required to store data about purchase orders are: ORDERID PRODID ©NIIT eXtensible Markup Language/Lesson 3/Slide 25 of 36
  • 26. Working with XML Schemas 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 The syntax for using the include element is given below: include id=ID schemaLocation=filename / ©NIIT eXtensible Markup Language/Lesson 3/Slide 26 of 36
  • 27. Working with XML Schemas Task 2: Identify a mechanism…documents. (Contd.) The include element can have multiple occurrences in an XSD document. The schema element is the parent element of the include element. The include element allows reference to any external schema, which is defined in the context of the same target namespace. A target namespace has a reference to a URI to which a schema belongs. The target namespace for a schema is declared using the targetNamespace attribute of the schema element. ©NIIT eXtensible Markup Language/Lesson 3/Slide 27 of 36
  • 28. Working with XML Schemas Task 2: Identify a mechanism …documents. (Contd.) The import element 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. The syntax for using the import element is given below: import id=ID namespace=namespace schemaLocation=filename / ©NIIT eXtensible Markup Language/Lesson 3/Slide 28 of 36
  • 29. Working with XML Schemas Task 2: Identify a mechanism …documents. (Contd.) The import element (Contd.) 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. 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. 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. ©NIIT eXtensible Markup Language/Lesson 3/Slide 29 of 36
  • 30. Working with XML Schemas Task 2: Identify a mechanism …documents. (Contd.) Result: In the given scenario, you can create reusable data types required for storing product ID and order ID in an XML schema. You can specify the restrictions on these data types. 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. ©NIIT eXtensible Markup Language/Lesson 3/Slide 30 of 36
  • 31. Working with XML Schemas 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. ©NIIT eXtensible Markup Language/Lesson 3/Slide 31 of 36
  • 32. Working with XML Schemas 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. ©NIIT eXtensible Markup Language/Lesson 3/Slide 32 of 36
  • 33. Working with XML Schemas 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]”. ©NIIT eXtensible Markup Language/Lesson 3/Slide 33 of 36
  • 34. Working with XML Schemas 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: name: Specifies the name of the user-defined attribute. ref: Contains a reference to a global attribute. 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. ©NIIT eXtensible Markup Language/Lesson 3/Slide 34 of 36
  • 35. Working with XML Schemas Summary (Contd.) type: Specifies the data type of the attribute. value: Specifies the default or fixed value for a user-defined attribute. The use attribute of the attribute element can take optional, default, fixed, 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. ©NIIT eXtensible Markup Language/Lesson 3/Slide 35 of 36
  • 36. Working with XML Schemas 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. ©NIIT eXtensible Markup Language/Lesson 3/Slide 36 of 36