Presentation is loading. Please wait.

Presentation is loading. Please wait.

XML Schema Laurea Magistrale in Informatica Chapter 04 Modulo del corso Thecnologies for Innovation.

Similar presentations


Presentation on theme: "XML Schema Laurea Magistrale in Informatica Chapter 04 Modulo del corso Thecnologies for Innovation."— Presentation transcript:

1 XML Schema Laurea Magistrale in Informatica Chapter 04 Modulo del corso Thecnologies for Innovation

2 XML Schema2 Agenda Schema characteristics Element Declaration Simple Element Restrictions Complex Elements Indicator Namespaces Schema characteristics Element Declaration Simple Element Restrictions Complex Elements Indicator Namespaces

3 XML Schema3 Schema è un termine generale, dal vocabolario inglese: a structured framework or plan Quando si parla di XML Schema si intende usualmente il W3C XML Schema Language … e il suo acronimo XSD (Xml Schema Definitiom) DTD, XML Schema, e RELAX NG sono tutti linguaggi di schema XML

4 XML Schema4 Very Simple xml schema It starts with an XML declaration Lestensione è.xsd e lelemento root è Namespace declaration Element Declaration The declaration makes use of our Schema namespace, and it uses attributes to provide information about the element we are defining XML SCHEMA ARE WELL_FORMED XML DOCUMENTS

5 XML Schema5 Schema characteristics Because XML Schemas are written using XML, that allows Schemas to be adopted quickly and easily by applications already using XML. Because XML is text based, it is easily transferable via common Internet file transfer methods, such as FTP and HTTP. In fact, Schemas are "optimized for interoperability" in this way because they are recursive, self- describing documents. XML Schemas is for datatyping.Datatypes allow you to specify that a piece of information has to be in a specific data format. Datatypes are a very powerful mechanism for placing constraints on your XML documents.

6 XML Schema6 Element Declarations The declaration uses the element type, which has a number of attributes that manipulate properties of the element. In the preceding declaration, there is a name attribute, which is used to specify the name of the element type being declared. There is also a type attribute, which is how you specify the datatype associated with an element using XML Schema.

7 XML Schema7 Valid Attributes for tag The element declaration in an XML Schema takes the form of the tag. That tag forms the start of any element declaration in your schema. The declaration can accept a number of attributes, each one designed to manipulate one or more of the properties that make up an element declaration.

8 XML Schema8 Default and Fixed attribute

9 XML Schema9 MaxOccurs and MinOccurs attribute

10 XML Schema10 REF and Type attribute

11 XML Schema11 Content Models: Elementi semplici e complessi Un elemento semplice contiene solo testo Non ha attributi Non contiene altri elementi Non può essere vuoto Ci possono essere varie restrizioni applicate al contenuto Un elemento complesso Può avere attributi Può essere vuoto, contenere testo, altri elementi, o sia testo che altri elementi.

12 XML Schema12 Definire un elemento semplice Un elemento semplice è definito come: dove: name è il nome dellelemento Valori comuni per type sono xs:booleanxs:integer xs:datexs:string xs:decimalxs:time

13 XML Schema13 Definire un attributo Gli attributi sono dichiarati sempre come tipi semplici Definito come dove: name e type sono gli stessi che per xs:element Altri attributi che gli elementi semplici possono avere: default=" default value " se nessun valore è specificato fixed=" value nessun altro valore può essere specificato use="optional" non richiesto (default) use="required" richiesto

14 XML Schema14

15 XML Schema15 Restrizioni (facets) La forma generale delle restrizioni è: (o xs:attribute )... the restrictions... Ad esempio:

16 XML Schema16 Restrizioni su numeri minInclusive -- numero deve essere di value minExclusive -- numero deve essere > di value maxInclusive -- numero deve essere di value maxExclusive -- numero deve essere < di value totalDigits -- numero deve avere value cifre fractionDigits -- numero deve avere non più di value cifre dopo il punto decimale

17 XML Schema17 Restrizioni su stringhe length -- la stringa deve contenere value caratteri minLength -- la stringa deve contenere almeno value caratteri maxLength -- la stringa deve contenere non più di value caratteri pattern -- value è una espressione regolare da soddisfare whiteSpace -- dice come trattare gli spazi bianchi value="preserve" li mantiene value="replace" rinpiazza con spazi value="collapse" rimuove gli spazi iniziali, finali e rimpiazza le sequenze con uno spazio singolo

18 XML Schema18 Enumerazioni Restringe il range di possibili valori ad una loro enumerazione Esempio:

19 XML Schema19 ESEMPIO : writing tip on a pen if we wanted to create an attribute for the size of the writing tip on a pen, we might want the size to be able to be expressed as a name, such as "Extra Fine" or as a decimal, such as ".05". size by name size by value

20 XML Schema20 UNIONE per creare un attributo di nome SIZE Element that use new attribute Legal value for the size attribute

21 XML Schema21 Elementi Complessi Un elemento complesso è definito da:... information about the complex type... Esempio:

22 XML Schema22 Kinds of complex elements empty elements elements that contain only other elements elements that contain only text elements that contain both other elements and text Note: Each of these elements may contain attributes as well!

23 XML Schema23 Examples of Complex Elements A complex XML element, "product", which is empty: A complex XML element, "employee", which contains only other elements: John Smith A complex XML element, "food", which contains only text: Ice cream A complex XML element, "description", which contains both elements and text: It happened on 03.03.99....

24 XML Schema24 Complex Element Definition: declared directly by naming the element If you use the method described above, only the "employee" element can use the specified complex type. Note that the child elements, "firstname" and "lastname", are surrounded by the indicator. This means that the child elements must appear in the same order as they are declared.

25 XML Schema25 Complex Element Definition: have a type attribute that refers to the name of the complex type to use If you use the method described above, several elements can refer to the same complex type

26 XML Schema26 Base a complex element on an existing complex element and add some elements

27 XML Schema27 Complex Empty Elements Product element declaration :

28 XML Schema28 Complex Type - Elements Only An "elements-only" complex type contains an element that contains only other elements. xs:element name="person" type="persontype"/> s

29 XML Schema29 Complex Text-Only Elements A complex text-only element can contain text and attributes..... OR.... Use the extension/restriction element to expand or to limit the base simple type for the element.

30 XML Schema30 Complex Types With Mixed Content A mixed complex type element can contain attributes, elements, and text Dear Mr. John Smith. Your order 1032 will be shipped on 2001-07-13.

31 XML Schema31 Indicator Order indicators: are used to define the order of the elements All Choice Sequence Occurrence indicators: are used to define the order of the elements maxOccurs minOccurs Group indicators: are used to define related sets of elements Group name attributeGroup name

32 XML Schema32 Order Indicator : ALL The indicator specifies that the child elements can appear in any order, and that each child element must occur only once Note: When using the indicator you can set the indicator to 0 or 1 and the indicator can only be set to 1

33 XML Schema33 Order Indicator : CHOICE The indicator specifies that either one child element or another can occur

34 XML Schema34 Order Indicator : SEQUENCE The indicator specifies that the child elements must appear in a specific order { "@context": "http://schema.org", "@type": "ImageObject", "contentUrl": "http://images.slideplayer.com/1/531159/slides/slide_34.jpg", "name": "XML Schema34 Order Indicator : SEQUENCE The indicator specifies that the child elements must appear in a specific order

35 XML Schema35 Occurrence Indicator : maxOccurs The indicator specifies the maximum number of times an element can occur The example above indicates that the "child_name" element can occur a minimum of one time (the default value for minOccurs is 1) and a maximum of ten times in the "person" element.

36 XML Schema36 Occurrence Indicator : minOccurs The indicator specifies the minimum number of times an element can occur The example above indicates that the "child_name" element can occur a minimum of zero times and a maximum of ten times in the "person" element. Tip: To allow an element to appear an unlimited number of times, use the maxOccurs="unbounded" statement:

37 XML Schema37 Working example Hege Refsnes Cecilie Tove Refsnes Hege Stale Jim Borge Stale Refsnes The XML file contains a root element named "persons". Inside this root element we have defined three "person" elements. Each "person" element must contain a "full_name" element and it can contain up to five "child_name" elements

38 XML Schema38 Group Indicator : Element/Attribute Group Element groups are defined with the group declaration, like this:... xs:group name="persongroup">

39 XML Schema39 The and elements are used to make EXTENSIBLE documents! They allow documents to contain additional elements that are not declared in the main XML schema. The following example is a fragment from an XML schema called "family.xsd". It shows a declaration for the "person" element. By using the element we can extend (after ) the content of "person" with any element:

40 XML Schema40 Perchè XML Schema? DTD fornisce specifiche deboli Nessuna restrizione sul contenuto del testo Poco controllo sui contenuti misti (mixed content, text + elements) Poco controllo sullordinamento degli elementi DTD è scritto in un formato non-XML Parser separati per DTD e XML XML Schema Definition Language risolve questi problemi Più controllo su strutture e contenuti XSD è scritto in XML

41 XML Schema41 Riferirsi ad uno schema Per la DTD il riferimento va prima del root element:... Per lXML Schema il riferimento va nel root element: (dove trovare lo Schema definition voluto)...

42 XML Schema42 Specifing Namespaces Are specified using the xmlns attribute to declare the Namespace with an element. The attribute takes the general form the element is the element for which we are declaring the Namespace The prefix is the prefix we will use with our element names the Namespace URI is the identifier of the Namespace itself. The prefix is actually optionalif it is left out, the Namespace declaration is considered the default Namespace, and all the elements in the document will be treated as members of that Namespace unless they are marked otherwise.

43 XML Schema43 Namespace URI Generally, this takes the form of a URL, which serves as a good unique identifier, because it includes the domain name, and is easily understood by Web-enabled software. The most common misconception resulting from the use of a URL here is that the URL necessarily points to something, when,in fact, it does not. The URL is simply used as a string to identify the Namespace it does not necessarily point to any specific document (although it can if you want it to) and there is no syntax or standard for creating a Namespace document to live on your server.

44 XML Schema44 Single Default Namespace

45 XML Schema45 Multiple Prefixed Namespaces To make all the Namespaces in the document require a prefix, we use the same basic structure as declaring a default Namespace, only we add the : prefix to the xmlns attribute

46 XML Schema46 The advantage of this method is that now both Namespaces are declared globally. That is because they are declared in the root element, and the default Namespace applies to any element without a prefix in the document. Because the second Namespace is also declared globally, any element in the document can be made part of that Namespace by appending the prefix. Default and Prefixed Namespaces

47 XML Schema47 default Namespace globally, and the secondNamespace declared locally

48 XML Schema48 list of the Namespaces for some of the technologies discussed


Download ppt "XML Schema Laurea Magistrale in Informatica Chapter 04 Modulo del corso Thecnologies for Innovation."

Similar presentations


Ads by Google