Presentation is loading. Please wait.

Presentation is loading. Please wait.

Underlying Technologies XML Is the Glue Program the Web XML Browse the Web HTML T C P/IP Connect the Web Technology Innovation ConnectivityPresentation.

Similar presentations


Presentation on theme: "Underlying Technologies XML Is the Glue Program the Web XML Browse the Web HTML T C P/IP Connect the Web Technology Innovation ConnectivityPresentation."— Presentation transcript:

1

2 Underlying Technologies XML Is the Glue Program the Web XML Browse the Web HTML T C P/IP Connect the Web Technology Innovation ConnectivityPresentation Connecting Applications FTP, E-mail, Gopher Web Pages Web Services

3 Introducing XML XML = Extensible Markup Language In information technology, extensible describes something, such as a program, programming language, or protocol, that is designed so that users or developers can expand or add to its capabilities Because XML is extensible, it can be used to create a wide variety of document types. XML enables document authors to create entirely new markup languages for describing specific types of data, including mathematical formulas, chemical molecular structures, music, recipes, etc.

4 Markup is a text-based notation for describing data Some XML-based markup languages include XHTML,MathML (for mathematics), VoiceXML™ (for speech), SMIL™ (the Synchronous Multimedia Integration Language—for multimedia presentations), CML (Chemical Markup Language—for chemistry) and XBRL (Extensible Business Reporting Language— for financial data exchange

5 1 2 3 4 5 6 7 Welcome to XML! 8 Line numbers are not part of XML document. We include them for clarity. Document begins with declaration that specifies XML version 1.0 Element message is child element of root element myMessage

6 XML documents contain text that represents content (i.e. data) such as welcome to xml !! It contains element that specify the document’s structure, such as mymessage XML documents delimit elements with start tags and end tags Start tag the element name in angle brackets End tag consists of the element name preceded by a forward slash (/)

7 Every XML document must have exactly one root element that contains all the other elements such as mymessage

8 VIEWING AND MODIFIFYING XML documents XML documents are highly portable. Viewing or modifying an XML document—which typically ends with the.xml filename extension—does not require special software. Any text editor that supports ASCII/Unicode characters can open XML documents for viewing and editing. One important characteristic of XML is that it is both human readable and machine readable.

9 Processing XML documents Processing an XML document requires a software program called an XML parser (or an XML processor) Parsers check an XML document’s syntax and enable software programs to process marked-up data XML syntax requires:  a single root element,  a start tag, and an end tag for each element  properly nested tags (i.e. the end tag for a nested element must appear before the end tag of the enclosing element)

10  XML is case sensitive. A document that conforms to this syntax is a well- formed XML document and is syntactically correct. Parser is built in IE7 and FF2

11 Validating XML Documents An XML document optionally can reference a document that defines that XML document’s structure. This document is either a Document Type Definition (DTD) or a schema. When an XML document references a DTD or schema, some parsers (called validating parsers) can read the DTD/schema and check that the XML document follows the structure that the DTD/schema defines. If the XML document conforms to the DTD/schema (i.e., the document has the appropriate structure), the XML document is valid.

12 Parsers that cannot check for document conformity against DTDs/schemas are non-validating parsers. If an XML parser (validating or non-validating) can process an XML document successfully, that XML document is well formed (i.e., it is syntactically correct). By definition, a valid XML document also is well-formed.

13 Elements title, date, author, summary and content are child elements of article. 1 2 3 4 5 6 7 8 Simple XML 9 10 September 19, 2001 11 12 13 Tem 14 Nieto 15 16 17 XML is pretty easy. 18 19 Once you have mastered XHTML, XML is easily 20 learned. You must remember that XML is not for 21 displaying information but for managing information. 22 23 24 Optional XML declaration. Element article is the root element.

14 We begin with the optional XML declaration on line 1. Value version indicates the XML version to which the document conforms. The current XML standard is version 1.0. Blank lines (line 2), white spaces and indentation help improve readability Comments (lines 3-4) begin with, can be placed anywhere Placing any characters including white spaces before the XML declaration is an error Line2(1-4) is the XML prolog lines(6-24) are the root element XML element and attribute names can be of any length and may contain letters, digits, underscores, hyphens and periods. However, XML names must begin with either a letter or an underscore.

15 Using either a space or a tab in an XML element or attribute name is an error using xml in any combination of uppercase or lower case letter at the beginning is error Parent(container)/ child relationship (all children at the same nesting level are siblings)

16 Viewing an xml Document Note that the XML document is simply a text file does not contain formatting information for the article. This is because XML is a technology only for structuring data. Formatting and displaying data from an XML document are application specific issues. For example, when Internet Explorer 7 loads an XML document, IE7’s parser msxml (Microsoft XML Core Services) parses and displays the document data.the firefox has a similar capability. Each browser has a built-in style sheet to format the data

17

18

19 Notice the minus sign (–) and plus sign (+). IE7 places these symbols next to all container elements. A minus sign indicates that IE7 is displaying that container element’s child elements. Clicking the minus sign next to an element causes IE7 to hide that container element’s children and replaces the minus sign with a plus sign. Clicking the plus sign next to an element causes IE7 to display that container element’s children and replaces the plus sign with a minus sign. The same can be found in FF2

20 Document Type Definitions A DTD enables an XML parser to verify whether an XML document is valid (i.e., its elements contain the proper attributes, are in the proper sequence, etc.)..

21 XML Markup for a Business letter Jane Doe Box 12345 15 Any Ave. Othertown Otherstate 67890 555-4321 This xml document references a DTD

22 John Doe 123 Main St. Anytown Anystate 12345 555-1234

23 Dear Sir: It is our privilege to inform you about our new database managed with XML. This new system allows you to reduce the load on your inventory list server by having the client machine perform the work of sorting and filtering the data. Please visit our website for availability and pricing. Sincerely, Ms. Jane Doe

24 : root element line(7-43) Root element letter contains child elements contact, salutation, paragraph, closing and signature.. Element with attribute ( type = ) (“sender”) Notes 1.Case sensitive 2.“ “ not ‘ ‘ 3. Attribute name Attribute value

25 Jane Doe Element with data between element’s tags

26 letter.dtd

27

28 To reference the DTD file we use : referenceRoot nameExternal file Name & location We have : ELEMENTEMPTY ATTLIST#RQUIRED CDATA#FIXED #IMPLIED#PCDATA

29 ELEMENT element type declaration defines the rules for element letter. In this case, letter contains one or more contact elements, one salutation element, one or more paragraph elements, one closing element and one signature element, in that sequence. The plus sign (+) occurrence indicator specifies that the DTD allows one or more occurrences of an element. asterisk (*), which indicates an optional element that can occur any number of times (zero or more) the question mark (?), which indicates an optional element that can occur at most once (zero or one occurrence)

30 If an element does not have an occurrence indicator, the DTD allows exactly one occurrence. The contact element definition (line 7) specifies that element contact contains child elements name, address1, address2, city, state, zip, phone and flag— in that order. The DTD requires exactly one occurrence of each element.

31 ATTLIST element type declaration to define an attribute (i.e., type) for the contact element. KEYWORD #IMPLIED specifies that if the parser finds a contact element without a type attribute, the parser can choose an arbitrary value for the attribute or ignore the attribute and the document will be valid.

32 KEYWORD #REQUIRED specifies that the attribute must be present in the element, and keyword KEYWORD #FIXED specifies that the attribute (if present) must have the given fixed value. For example, indicates that attribute zip must have the value 01757 for the document to be valid KEYWORD# DEFAULTThe attribute has a default value

33 CDATA CDATA specifies that attribute type contains character data (i.e.,a string) which indicates that the parser will not process the data, but will pass the data to the application without modification. #PCDATA specifies that the element can contain parsed character data (i.e., text). Parsable character data should not contain markup characters, such as less than ( ) and ampersand (&). The document author should replace any markup character with its corresponding entity (i.e., <, > or &). Appendix A contains special character

34 Entity ReferencesCharacter << >> && "" &apos;' Apos to denote the apostrophe

35 KEYWORD EMPTY specifies that the element does not contain any data. Attributes commonly contain data that the empty element describes FOR EXAMPLE the gender attribute value must be one of the enumerated values (M or F) and the default value is M

36 Wrapping If the DTD is to be included in your XML source file, it should be wrapped in a DOCTYPE definition with the following syntax: example: <!DOCTYPE note [ ]>

37 Tove Jani Reminder Don't forget me this weekend

38

39

40 This XML document has a reference to a DTD: Tove Jani Reminder Don't forget me this weekend! A Reference to a DTD

41 A DTD File

42

43 XML Schema is an XML-based alternative to DTD. An XML schema describes the structure of an XML document. The XML Schema language is also referred to as XML Schema Definition (XSD). An XML SCHEMA

44 The purpose of an XML Schema is to define the legal building blocks of an XML document, just like a DTD. An XML Schema: defines elements that can appear in a document defines attributes that can appear in a document defines which elements are child elements defines the order of child elements What is an XML Schema?

45 defines the number of child elements defines whether an element is empty or can include text defines data types for elements and attributes defines default and fixed values for elements and attributes

46 We think that very soon XML Schemas will be used in most Web applications as a replacement for DTDs. Here are some reasons: XML Schemas are extensible to future additions XML Schemas are richer and more powerful than DTDs XML Schemas are written in XML XML Schemas support data types XML Schemas support namespaces XML Schemas are much more powerful than DTDs. XML Schemas are the Successors of DTDs

47 Tove Jani Reminder Don't forget me this weekend! A Simple XML Document

48 An XML Schema

49 Tove Jani Reminder Don't forget me this weekend! A Reference to an XML Schema

50 The element is the root element of every XML Schema:...... The Element

51 The element may contain some attributes. A schema declaration often looks something like this:......

52 xmlns:xs=http://www.w3.org/2001/XMLSchemahttp://www.w3.org/2001/XMLSchema indicates that the elements and data types used in the schema come from the "http://www.w3.org/2001/XMLSchema" namespace. It also specifies that the elements and data types that come from the "http://www.w3.org/2001/XMLSchema" namespace should be prefixed with xs:

53 targetNamespace=http://www.w3schools.comhttp://www.w3schools.com indicates that the elements defined by this schema (note, to, from, heading, body.) come from the "http://www.w3schools.com" namespace.

54 xmlns=http://www.w3schools.comhttp://www.w3schools.com indicates that the default namespace is "http://www.w3schools.com". elementFormDefault="qualified“ indicates that any elements used by the XML instance document which were declared in this schema must be namespace qualified.

55 Referencing a Schema in an XML Document <note xmlns=http://www.w3schools.comhttp://www.w3schools.com specifies the default namespace declaration. This declaration tells the schema-validator that all the elements used in this XML document are declared in the "http://www.w3schools.com" namespace.

56 xmlns:xsi=http://www.w3.org/2001/XMLSchema-instancehttp://www.w3.org/2001/XMLSchema-instance Another very important way in which namespaces are used in conjunction with XML Schema is through the XML Instance namespace. There are a number of elements described by the XML Schema: Structures recommendation which are designed to link with a Schema to a specific XML instance document. Those elements have actually been given their own namespace: http://www.w3.org/2001/XMLSchema-instance The XML Instance namespace is a very important one, even though it does not contain many elements. It is so important because it is how you associate an XML Schema with a document. xsi

57 Once you have the XML Schema Instance namespace available: You can use attributes defined in the XML Schema: xsi:schemaLocation xsi:noNamespaceSchemaLocation

58 xsi:schemaLocation The XML instance schemaLocation attribute is used to specify the location of an XML Schema associated with an XML document. The attribute value is a pair of URIs, the first of which is the targetNamespace for the XML Schema, and the second is the URI that points to the location of the Schema. xsi:schemaLocation="http://www.w3schools.com note.xsd"> Example

59 noNamespaceSchemaLocation attribute is very similar to the schemaLocation attribute, in that it allows you to specify the location of a Schema for use with your document. However, since a Schema is not required to have a targetNamespace, this attribute can be used for Schema that do not have a namespace xsi:noNamespaceSchemaLocation

60 This is family.xsd file in the same folder with xml file … Xml file : Example Root element

61 This is note.xsd file in the same folder with xml file:...... Example

62 Xml file Root element Target name space

63 Hello From XML This is an XML document! We can use also UTF-16 or ISO-8859-1 Character Encodings:

64 The structures that make up an XML Schema are called components, and every XML Schema is essentially a set of components which outline the constraints placed on the content of an XML document. Documents which contain XML elements and attributes are XML instance documents, and Schema can constrain those instances The Components of XML Schema

65

66 A simple element is an XML element that can contain only text. It cannot contain any other elements or attributes. However, the "only text" restriction is quite misleading. The text can be of many different types. It can be one of the types included in the XML Schema definition (boolean, string, date, etc.), or it can be a custom type that you can define yourself. You can also add restrictions (facets) to a data type in order to limit its content, or you can require the data to match a specific pattern. A Simple Element

67 The syntax for defining a simple element is: where xxx is the name of the element and yyy is the data type of the element. XML Schema has a lot of built-in data types. The most common types are: xs:string xs:decimal xs:integer xs:boolean xs:date xs:time Defining a Simple Element

68 Here are some XML elements : Refsnes 36 1970-03-27 And here are the corresponding simple element definitions: Example

69 Simple elements may have a default value OR a fixed value specified. A default value is automatically assigned to the element when no other value is specified. In the following example the default value is "red": A fixed value is also automatically assigned to the element, and you cannot specify another value. In the following example the fixed value is "red": Default and Fixed Values for Simple Elements

70 What is an Attribute? Simple elements cannot have attributes. If an element has attributes, it is considered to be of a complex type. But the attribute itself is always declared as a simple type. The syntax for defining an attribute is: where xxx is the name of the attribute and yyy specifies the data type of the attribute. XML Schema has a lot of built-in data types. The most common types are: xs:string xs:decimal xs:integer xs:boolean xs:date xs:time An Attribute

71 Here is an XML element with an attribute: Smith And here is the corresponding attribute definition: Example

72 Attributes may have a default value OR a fixed value specified. A default value is automatically assigned to the attribute when no other value is specified. In the following example the default value is "EN": A fixed value is also automatically assigned to the attribute, and you cannot specify another value. In the following example the fixed value is "EN": Default and Fixed Values for Attributes

73 Attributes are optional by default. To specify that the attribute is required, use the "use" attribute: Optional and Required Attributes

74 When an XML element or attribute has a data type defined, it puts restrictions on the element's or attribute's content. If an XML element is of type "xs:date" and contains a string like "Hello World", the element will not validate. With XML Schemas, you can also add your own restrictions to your XML elements and attributes. These restrictions are called facets Restrictions on Content

75 The following example defines an element called "age" with a restriction. The value of age cannot be lower than 0 or greater than 120: Restrictions on Values

76 To limit the content of an XML element to a set of acceptable values, we would use the enumeration constraint. The example below defines an element called "car" with a restriction. The only acceptable values are: Audi, Golf, BMW: Restrictions on a Set of Values

77 The example above could also have been written like this: Note: In this case the type "carType" can be used by other elements because it is not a part of the "car" element.

78 To limit the content of an XML element to define a series of numbers or letters that can be used, we would use the pattern constraint. The example below defines an element called "letter" with a restriction. The only acceptable value is ONE of the LOWERCASE letters from a to z: Restrictions on a Series of Values

79 The next example defines an element called "initials" with a restriction. The only acceptable value is THREE of the UPPERCASE letters from a to z:

80 The next example also defines an element called "initials" with a restriction. The only acceptable value is THREE of the LOWERCASE OR UPPERCASE letters from a to z:

81 The next example defines an element called "choice" with a restriction. The only acceptable value is ONE of the following letters: x, y, OR z:

82 The next example defines an element called "prodid" with a restriction. The only acceptable value is FIVE digits in a sequence, and each digit must be in a range from 0 to 9:

83 The example below defines an element called "letter" with a restriction. The acceptable value is zero or more occurrences of lowercase letters from a to z:

84 The next example defines an element called "gender" with a restriction. The only acceptable value is male OR female:

85 The next example defines an element called "password" with a restriction. There must be exactly eight characters in a row and those characters must be lowercase or uppercase letters from a to z, or a number from 0 to 9:

86 The next example also defines an element called "letter" with a restriction. The acceptable value is one or more pairs of letters, each pair consisting of a lower case letter followed by an upper case letter. For example, "sToP" will be validated by this pattern, but not "Stop" or "STOP" or "stop":

87 To specify how whitespace characters should be handled, we would use the whiteSpace constraint. This example defines an element called "address" with a restriction. The whiteSpace constraint is set to "preserve", which means that the XML processor WILL NOT remove any white space characters: Restrictions on Whitespace Characters

88 This example also defines an element called "address" with a restriction. The whiteSpace constraint is set to "replace", which means that the XML processor WILL REPLACE all white space characters (line feeds, tabs, spaces, and carriage returns) with spaces:

89 This example also defines an element called "address" with a restriction. The whiteSpace constraint is set to "collapse", which means that the XML processor WILL REMOVE all white space characters (line feeds, tabs, spaces, carriage returns) are replaced with spaces, leading and trailing spaces are removed, and multiple spaces are reduced to a single space):

90 To limit the length of a value in an element, we would use the length, maxLength, and minLength constraints. This example defines an element called "password" with a restriction. The value must be exactly eight characters: Restrictions on Length

91 This example defines another element called "password" with a restriction. The value must be minimum five characters and maximum eight characters:

92 Data types Page (537)

93

94 ConstraintDescription enumerationDefines a list of acceptable values fractionDigitsSpecifies the maximum number of decimal places allowed. Must be equal to or greater than zero Length Specifies the exact number of characters or list items allowed. Must be equal to or greater than zero maxExclusiveSpecifies the upper bounds for numeric values (the value must be less than this value) maxInclusiveSpecifies the upper bounds for numeric values (the value must be less than or equal to this value) maxLengthSpecifies the maximum number of characters or list items allowed. Must be equal to or greater than zero Restrictions for Data types

95 minExclusiveSpecifies the lower bounds for numeric values (the value must be greater than this value) minInclusiveSpecifies the lower bounds for numeric values (the value must be greater than or equal to this value) minLengthSpecifies the minimum number of characters or list items allowed. Must be equal to or greater than zero patternDefines the exact sequence of characters that are acceptable totalDigitsSpecifies the exact number of digits allowed. Must be greater than zero whiteSpaceSpecifies how white space (line feeds, tabs, spaces, and carriage returns) is handled Restrictions for Data types(cont.)

96 1.Create a definition in XML SCHEMA for: the company_id simple type element which must be all digits and must be exactly 6 digits long. Paperback 450 2. Identify and correct the error(s) in each of the following: a) This is my custom markup b) c) The next part of code defines an element called “myname" with a restriction. The acceptable value is one or more pairs of letters, each pair consisting of an upper case letter followed by an lower case letter.

97 3. In No.(2) part (c) Which of the following will be validated by this pattern: AsLaMa aSLaMA ASLAma aslaMa


Download ppt "Underlying Technologies XML Is the Glue Program the Web XML Browse the Web HTML T C P/IP Connect the Web Technology Innovation ConnectivityPresentation."

Similar presentations


Ads by Google