XML-Schema-Elements_Types_Attributes.pptx

AkshayKumar100378 5 views 14 slides May 27, 2024
Slide 1
Slide 1 of 14
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14

About This Presentation

Rules to write XML tags


Slide Content

XML-Schema

XML-Schema An XML schema, commonly known as an XML Schema Definition (XSD), formally describes what a given XML document can contain. The XML schema defines the shape, or structure, of an XML document, along with rules for data content and semantics such as what fields an element can contain, which sub elements it can contain and how many items can be present. 

 XML  Elements Elements are the main building block of all XML documents, containing the data and determine the structure of the instance document. An element can be defined within an XSD as follows: <xs:element name="x" type="y" />  XSD must have a 'name' property, which is the tag name that will appear in the XML document. The 'type' property provides the description of what type of data can be contained within the element when it appears in the XML document.  There are a number of predefined simple types, such as xs:string, xs:integer, xs:boolean and xs:date

Specifying Element  Cardinality It is possible to constrain the number of instances (cardinality) of an XML element that appear in an XML document. The cardinality is specified using the minOccurs and maxOccurs attributes, and allows an element to be specified as mandatory, optional, or can appear up to a set number of times. The default values for minOccurs and maxOccurs is 1. Therefore, if both the minOccurs and maxOccurs attributes are absent, as in all the previous examples, the element must appear once and once only.

Simple Types <xs:element name="Customer_dob" type="xs:date" /> <xs:element name="Customer_address" type="xs:string" /> <xs:element name="Supplier_phone" type="xs:integer" /> <xs:element name="Supplier_address" type="xs:string" />

Complex Types

Defining  Compositors Compositors provide rules that determine how and in what order there children can appear within XML document. There are three types of compositors <xs:sequence>, <xs:choice> and <xs:all>.

Defining XML  Attributes An attribute provides extra information within an element. Attributes have name and type properties and are defined within an XSD as follows: <xs:attribute name="x" type="y" /> <xs:attribute name="ID" type="xs:string" /> <xs:attribute name="ID" type="xs:string" use="optional" />

Sample XML Schema (XSD): <xs:element name="Shape"> <xs:complexType> <xs:sequence> <xs:element name="Point" minOccurs="1" maxOccurs="unbounded"> <xs:complexType> <xs:attribute name="x" type="xs:int" /> <xs:attribute name="y" type="xs:int" /> </xs:complexType> </xs:element> </xs:sequence> <xs:attribute name="Colour" type="xs:string" /> </xs:complexType> </xs:element>

Sample XML: <Shape Colour="Black"> <Point x="0" y="0" /> <Point x="100" y="0" /> <Point x="50" y="50" /> </Shape>