46

XML Schemas

Embed Size (px)

DESCRIPTION

XML Schemas Lanaguage

Citation preview

Page 1: XML Schemas
Page 2: XML Schemas

<?xml version=„1.0‟ encoding=“UTF-8”?>

<!-- Human Resource data-->

<HumanResource>

<!-- Information for a person-->

<Person id=„1‟ slary=“500”>

<FirstName>John</FirstName>

<MidName></MidName>

<LastName>Doe</LastName>

<Position>Manager</Position>

</Person>

</HumanResource>

Document Type

Page 3: XML Schemas
Page 4: XML Schemas
Page 5: XML Schemas
Page 6: XML Schemas

<?xml version=”1.0”?>

<name>

<first>

John

</first>

<middle>

Johansen

</middle>

<last>

Doe

</last>

</name>

<?xml version=”1.0”?><schema xmlns=”http://www.w3.org/2001/XMLSchema”

xmlns:target=”http://www.exam.com/name”

targetNamespace=”http://www.exam.com/name”

elementFormDefault=”qualified”>

<element name=”name”>

<complexType>

<sequence>

<element name=”first” type=”string”/>

<element name=”middle” type=”string”/>

<element name=”last” type=”string”/>

</sequence>

</complexType>

</element>

</schema>

Page 7: XML Schemas

<rootElement

xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”

xsi:schemaLocation=“list of namespace-location pairs”

>

</rootElement>

Page 8: XML Schemas

<rootElement

xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”

xsi:noNamespaceSchemaLocation=“location”

>

</rootElement>

Page 9: XML Schemas

<?xml version=”1.0”?>

<name>

<first>

John

</first>

<middle>

Johansen

</middle>

<last>

Doe

</last>

</name>

<?xml version=”1.0”?><schema xmlns=”http://www.w3.org/2001/XMLSchema”

xmlns:target=”http://www.exam.com/name”

targetNamespace=”http://www.exam.com/name”

elementFormDefault=”qualified”>

<element name=”name”>

<complexType>

<sequence>

<element name=”first” type=”string”/>

<element name=”middle” type=”string”/>

<element name=”last” type=”string”/>

</sequence>

</complexType>

</element>

</schema>

Page 10: XML Schemas

<schema

targetNamespace=“URI”

attributeFormDefault=“qualified or unqualified”

elementFormDefault=“qualified or unqualified”

version=“version number”>

</schema>

<schema xmlns=”http://www.w3.org/2001/XMLSchema”>

<xs:schema xmlns:xs=”http://www.w3.org/2001/XMLSchema”>

<xsd:schema xmlns:xsd=”http://www.w3.org/2001/XMLSchema”>

Page 11: XML Schemas

<element

name=”name of the element”

type=”global type”

ref=”global element declaration”

form=”qualified or unqualified”

minOccurs=”non negative number”

maxOccurs=”non negative number or „unbounded‟”

default=”default value”

fixed=”fixed value”>

Page 12: XML Schemas

<element

name=”name of the element”

type=”global type”

ref=”global element declaration”

form=”qualified or unqualified”

minOccurs=”non negative number”

maxOccurs=”non negative number or „unbounded‟”

default=”default value”

fixed=”fixed value”>

Page 13: XML Schemas
Page 14: XML Schemas
Page 15: XML Schemas
Page 16: XML Schemas

birthday=“02-10-2011”

<phone>043678002</phone>

Page 17: XML Schemas

<simpleType

name=”name of the simpleType”

final=”#all or list or union or restriction”>

Page 18: XML Schemas

<restriction

base=”name of the simpleType you are deriving from”>

Page 19: XML Schemas
Page 20: XML Schemas

Facet Description

minExclusive Allows you to specify the minimum value for your type that excludes the value you specify

minInclusive Allows you to specify the minimum value for your type that includes the value you specify

maxExclusive Allows you to specify the maximum value for your type that excludes the value you specify

maxInclusive Allows you to specify the maximum value for your type that includes the value you specify

totalDigits Allows you to specify the total number of digits in a numeric type

fractionDigits Allows you to specify the number of fractional digits in a numeric type

length Allows you to specify the number of items in a list type or the number of characters in a string type

minLength Allows you to specify the minimum number of items in a list type or the minimum number of

characters in a string type

maxLength Allows you to specify the maximum number of items in a list type or the maximum number of

characters in a string type

enumeration Allows you to specify an allowable value in an enumerated list

whitespace Allows you to specify how whitespace should be treated within the type

pattern Allows you to restrict string types using regular expressions

Page 21: XML Schemas

<simpleType name="myIntegerType">

<restriction base="integer">

<minInclusive value="10000"/>

<maxInclusive value="99999"/>

</restriction>

</simpleType>

Page 22: XML Schemas

<simpleType

name="stockKeepingUnitType">

<restriction base="string">

<pattern value="\d{3}-[A-Z]{2}"/>

</restriction>

</simpleType>

Page 23: XML Schemas

<simpleType name=“phoneType”>

<restriction base=”string”>

<enumeration value=”Home”/>

<enumeration value=”Work”/>

<enumeration value=”Cell”/>

<enumeration value=”Fax”/>

</restriction>

</simpleType>

Page 24: XML Schemas

<list

itemType=”name of simpleType used for validating items in the list”>

<simpleType name=”phoneListType”>

<list itemType=”exam:phoneType”/>

</simpleType>

Page 25: XML Schemas

<union

memberTypes=”whitespace separated list of types”>

Page 26: XML Schemas

<simpleType name=”UnknownString”>

<restriction base=”string”>

<enumeration value=”Unknown”/>

</restriction>

</simpleType>

<simpleType name=”UnknownOrFloatType”>

<union memberTypes=”float exam:UnknownString”/>

</simpleType>

Page 27: XML Schemas
Page 28: XML Schemas

content model

attribute list

Page 29: XML Schemas

<phone>043678002</phone>

<element name=”name”>

<complexType>

<sequence>

<element name=”first” type=”string”/>

<element name=”middle” type=”string”/>

<element name=”last” type=”string”/>

</sequence>

<attribute name=”title” type=”string”/>

</complexType>

</element>

Page 30: XML Schemas
Page 31: XML Schemas
Page 32: XML Schemas

<sequence>

<element name=”first” type=”string”/>

<element name=”middle” type=”string”/>

<element name=”last” type=”string”/>

</sequence>

<!ELEMENT name (first, middle, last)>

Page 33: XML Schemas

<choice>

<element name=”first” type=”string”/>

<element name=”middle” type=”string”/>

<element name=”last” type=”string”/>

</choice>

<!ELEMENT name (first| middle| last)>

Page 34: XML Schemas
Page 35: XML Schemas

<group name=”NameGroup”>

<sequence>

<element name=”first” type=”string”/>

<element name=”middle” type=”string”/>

<element name=”last” type=”string”/>

</sequence>

</group>

<element name=”name”>

<complexType>

<group ref=”target:NameGroup”/>

<attribute name=”title” type=”string”/>

</complexType>

</element>

Page 36: XML Schemas

<complexType name="mixedType" mixed="true">

<choice maxOccurs="unbounded" minOccurs="0">

<element name=“b" type="string"/>

<element name="i" type="string"/>

<element name="u" type="string"/>

</choice>

<attribute ref="class"/>

</complexType>

<!ELEMENT description (#PCDATA | b | i | u)*>

Page 37: XML Schemas

<element name=“br”>

<complexType>

<attribute name=”title” type=”string”/>

<complexType>

</element>

<!ELEMENT br EMPTY>

Page 38: XML Schemas

<all>

<element name=”first” type=”string”/>

<element name=”middle” type=”string”/>

<element name=”last” type=”string”/>

</all>

Page 39: XML Schemas
Page 40: XML Schemas

<attribute

name=”name of the attribute”

type=”global type”

ref=”global attribute declaration”

form=”qualified or unqualified”

use=”optional or prohibited or required”

default=”default value”

fixed=”fixed value”>

Page 41: XML Schemas

<attribute name=”title”>

<simpleType>

<!-- type information -->

</simpleType>

</attribute>

<attribute name=”title” type=”string”/>

Page 42: XML Schemas

<attributeGroup name=”ContactsAttributes”>

<!-- attribute declarations go here -->

</attributeGroup>

attributGroups may not recursively refer to themselves

<attributeGroup name=”AttGroup1”>

<attributeGroup ref=”target:AttGroup1”/>

</attributeGroup >

<attributeGroup name=”AttGroup1”>

<attributeGroup ref=”target:AttGroup2”/>

</attributeGroup >

<attributeGroup name=”AttGroup2”>

<attributeGroup ref=”target:AttGroup1”/>

</attributeGroup >

Page 43: XML Schemas
Page 44: XML Schemas

<import

namespace=””

schemaLocation=””>

<import

namespace=”http://www.example.com/name”

schemaLocation=”name8.xsd”/>

Page 45: XML Schemas

<include

schemaLocation=””>

<include

schemaLocation=”contact_tags.xsd”/>

Page 46: XML Schemas