Specify: – the structure of instance documents – the datatype of each element/attribute
XML File XML Schema
<xsd:schema xmlns:xsd=" targetNamespace=" xmlns=" elementFormDefault="qualified"> All XML Schemas have "schema" as the root element.
<xsd:schema xmlns:xsd=" targetNamespace=" xmlns=" elementFormDefault="qualified"> The elements and datatypes that are used to construct schemas - schema - element - complexType - sequence - string come from the namespace
Indicates that the elements defined by this schema - BookStore - Book - Title - Author - Date - ISBN - Publisher are to go in the namespace <xsd:schema xmlns:xsd=" targetNamespace=" xmlns=" elementFormDefault="qualified">
Bookstore is the default <xsd:schema xmlns:xsd=" targetNamespace=" xmlns=" elementFormDefault="qualified"> This is referencing a Book element declaration. The Book in what namespace? Since there is no namespace qualifier it is referencing the Book element in the default namespace, which is the targetNamespace! Thus, this is a reference to the Book element declaration in this schema.
<schema xmlns=" targetNamespace=" xmlns:bk=" elementFormDefault="qualified"> Here, XMLSchema is the Default
There are 3 types - Build-in typee.g. integer,string… - simpleTypeextensions of the build-in types e.g. Telephone, Binary -complexTypeelements with child elements or attributes 21
There are 3 types - Build-in typee.g. integer,string - simpleTypeextensions of the build-in types e.g. Telephone, Binary -complexTypeelements with child elements or attributes 21
There are 3 types - Build-in typee.g. integer,string - simpleTypeextensions of the build-in types e.g. Telephone, Binary -complexTypeelements with child elements or attributes My Life and Times Paul McCartney
<xsd:schema xmlns:xsd=" targetNamespace=" xmlns=" elementFormDefault="qualified"> complexType when: -Element has attribute -Element has child elements Inline, without name - cannot be reused
<xsd:schema xmlns:xsd=" targetNamespace=" xmlns=" elementFormDefault="qualified"> Global Global with Name - can be reused
<xsd:schema xmlns:xsd=" targetNamespace=" xmlns=" elementFormDefault="qualified"> My Life and Times build-in type
Primitive Datatypes – string – boolean – decimal – float – double – duration – dateTime – time – date – gYearMonth – gYear – gMonthDay Atomic, built-in – "Hello World" – {true, false, 1, 0} – 7.08 – 12.56E3, 12, 12560, 0, -0, INF, -INF, NAN – P1Y2M3DT10H30M12.3S – format: CCYY-MM-DDThh:mm:ss – format: hh:mm:ss.sss – format: CCYY-MM-DD – format: CCYY-MM – format: CCYY – format: --MM-DD Note: 'T' is the date/time separator INF = infinity NAN = not-a-number
<xsd:schema xmlns:xsd=" targetNamespace=" xmlns=" elementFormDefault="qualified"> These elements refer to elements defined globaly in the schema
<xsd:schema xmlns:xsd=" targetNamespace=" xmlns=" elementFormDefault="qualified"> minOccurs, maxOccurs - Default=1 Bookstore can now contain a sequence of books
<xsd:schema xmlns:xsd=" targetNamespace=" xmlns=" elementFormDefault="qualified"> AND OR AND OR
This simpleType uses EarthSurfaceElevation as its base type.
Equivalent Inline without name Global with name
… 1 2 … 3 Can be: -Build-in type -simpleType already defined -complexType already defined
<xsd:schema xmlns:xsd=" targetNamespace=" xmlns=" elementFormDefault="qualified"> BookPublication is a Publication that also contains ISBN and Publisher elements
SingleAuthorPublication is a Publication that can contain only one Author Many Authors Only One Author
Illusions: The Adventures of a Reluctant Messiah Richard Bach Dell Publishing Co. Natural Health 1999 The First and Last Freedom J. Krishnamurti Harper & Row Book and Magazine elements can now be used wherever Publication element is used
Attributes apply to the element they are nested within My Life and Times Paul McCartney July, McMillin Publishing Attributes are defined like elements but can only be of build-in type or simpleType (never complexType)
required optional prohibited The "use" attribute must be optional if you use default or fixed. xsd:string xsd:integer xsd:boolean... … 1 2 Can be: -Build-in type -SimpleType already defined
Ομαδοποίηση elements
<xsd:schema xmlns:xsd=" targetNamespace=" xmlns=" elementFormDefault="qualified"> <xsd:schema xmlns:xsd=" targetNamespace=" xmlns=" elementFormDefault="qualified"> Transportation can contain one(and only one) of the train, plane, automobile elements Binary-string can contain a sequence of zero and one elements
<xsd:schema xmlns:xsd=" targetNamespace=" xmlns=" elementFormDefault="qualified"> means that Book must contain all five child elements, but they may occur in any order.
Now in the instance XML file we can add after the Publisher element any element of our choice
<BookStore xmlns=" xmlns:xsi=" xsi:schemaLocation= " BookRetailers.org BookSeller.xsd repository.org SchemaRepository.xsd"> My Life and Times Paul McCartney McMillin Publishing Roger Costello Illusions: The Adventures of a Reluctant Messiah Richard Bach Dell Publishing Co.
Now in the instance XML file we can add in a Book element any attribute of our choice
NotePad++ plus/files/notepad%2B%2B%20releases%20binary/npp% %20bin/npp Installer.e xe/download External Libraries (extract in Notepad++ install folder) plugins/files/XML%20Tools/External%20libs/ext_libs.zip/download XML Tools plugin (extract in Notepad++/plugins folder) plugins/files/XML%20Tools/Xml%20Tools% %20r764%20Unicode%20Beta1/xmltools_ 2.3.1_r764_unicode_beta1.zip/download