Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Xml schema

XML Schema,Elements,Complex Type,Global Type,xs:all,referencing

  • Login to see the comments

Xml schema

  2. 2. XMLSCHEMA • It is also called as XSD(Xml Schema Definition). • It is used to describe and validate the structure and content of xml data • Xml schema defines the elements, attributes, and data types. • <xs:schema xmlns:xs=“”>
  3. 3. ELEMENTS • Elements are building blocks of xml document. An element can be defined with in an XSD. • <xs:element name=“x” type=“y”/> • Three types of elements: 1.Simple Type 2.Complex Type 3.Global Type 1. Simple Type These are used only in the context of text. They are  xs:integer  xs:boolean  xs:string  xs:date  <xs:element name=“phone_number” type=“xs:int”/> – name is the name of the element • Other attributes a simple element may have: – default="default value" if no other value is specified – fixed="value" no other value may be specified
  4. 4. Complex Type • They are container for other element definition. • They allow us to specify which child elements an element can contain and to provide some structure within your document.
  5. 5. Global Type • With global type, you can define a single type in your document, which can be used by all other references. • For example, suppose you want to generalize the person and company for different addresses of the company. In such case, you can define a general type as below:
  6. 6. Attributes • Attributes in XSD provide extra information within an element. Attributes have name and type property as shown below: • <xs:attribute nam e="x" type="y"/>
  7. 7. 7 xs:all • xs:all allows elements to appear in any order • <xs:element name="person"> <xs:complexType> <xs:all> <xs:element name="firstName" type="xs:string" /> <xs:element name="lastName" type="xs:string" /> </xs:all> </xs:complexType> </xs:element> • Despite the name, the members of an xs:all group can occur once or not at all • You can use minOccurs="0" to specify that an element is optional (default value is 1) – In this context, maxOccurs is always 1
  8. 8. 8 Referencing • Once you have defined an element or attribute (with name="..."), you can refer to it with ref="..." • Example: – <xs:element name="person"> <xs:complexType> <xs:all> <xs:element name="firstName" type="xs:string" /> <xs:element name="lastName" type="xs:string" /> </xs:all> </xs:complexType> </xs:element> – <xs:element name="student" ref="person"> – Or just: <xs:element ref="person">
  9. 9. 9 Text element with attributes • If a text element has attributes, it is no longer a simple type – <xs:element name="population"> <xs:complexType> <xs:simpleContent> <xs:extension base="xs:integer"> <xs:attribute name="year” type="xs:integer"> </xs:extension> </xs:simpleContent> </xs:complexType> </xs:element>