EXtensible Markup Language (XML) - Part 3

A well-formed XML document is a document that conforms to the XML syntax rules, like: it must begin with the XML declaration it must have one unique root element start-tags must have matching end-tags elements are case sensitive all elements must be closed all elements must be properly nested all attribute values must be quoted entities must be used for special characters

ppt48 trang | Chia sẻ: huongnt365 | Lượt xem: 531 | Lượt tải: 0download
Bạn đang xem trước 20 trang tài liệu EXtensible Markup Language (XML) - Part 3, để xem tài liệu hoàn chỉnh bạn click vào nút DOWNLOAD ở trên
CSC 330 E-CommerceTeacher Ahmed Mumtaz Mustehsan GM-IT CIIT Islamabad Virtual Campus, CIIT COMSATS Institute of Information TechnologyT2-Lecture-5eXtensable Markup Language (XML) Part - IIIFor Lecture Material/Slides Thanks to: www.w3schools.comObjectivesPart 1: Review The basics of creating an XML documentPart 2: Imposing Structure on XML Documents using Document Type Definition DTDPart 3:Strengthening the data-modeling capabilities of XML Using XML Schemas T2-Lecture-5 Ahmed Mumtaz Mustehsan www.w3schools.com1-3Part 1: Review The basics of creating an XML documentT2-Lecture-5 Ahmed Mumtaz Mustehsan www.w3schools.com1-4Part 1: A review of XMLAn Extensible Markup Language (XML) document describes the structure of data. XML and HTML have a similar syntax both derived from SGMLXML has no mechanism to specify the format for presenting data to the userAn XML document resides in its own file with an ‘.xml’ extensionT2-Lecture-5 Ahmed Mumtaz Mustehsan www.w3schools.com1-5Main Components of an XML DocumentElements: Attributes: Entities: < ( Ahmed Mumtaz 9251-2233-44 mumtaz@yahoo.com Malik Riaz khan 9251-123-4450 mriaz@yahoo.com T2-Lecture-5 Ahmed Mumtaz Mustehsan www.w3schools.com1-9Important Features of XMLNo fixed set of tagsUser is allowed to introduce New tags Already defined set of tags can also be used Namespaces facilitate uniform and coherent descriptions of dataFor example, a namespace for address books determines to use of : or or T2-Lecture-5 Ahmed Mumtaz Mustehsan www.w3schools.com1-10Features of XML (cont’d)XML supports internationalization through UnicodeWeb services (e.g., e-commerce) require exchanging data between various applications that run on different platforms.XML (with the support of namespaces) is the best option for data exchange on the Web.XML is a data model Similar to the semi-structured-data-modelXML has follow the concept of DTD and the more impressive XML SchemaT2-Lecture-5 Ahmed Mumtaz Mustehsan www.w3schools.com1-11XML familyLimited styling of XML can be done with CSS Document Type Definitions (DTDs) impose structure on XML documentsXML Schemas strengthen the data-modeling capabilities of XMLXPath is a language for accessing XML documentsXLink and XPointer support cross-referencesXSLT is a language for transforming XML documents into other XML documents such as XHTML, for viewing XML filesXQuery is a language for querying XML documentsT2-Lecture-5 Ahmed Mumtaz Mustehsan www.w3schools.com1-12DTD : (Document Type Definition)Imposing Structure onXML DocumentsusingXML defines structure of the documentSome XML files only contain text documents with tags that contain metadata and describe the structure Example: e-Commerce Business, Technology and Society Laudon Kenneth PEARSON 78.99T2-Lecture-5 Ahmed Mumtaz Mustehsan www.w3schools.com1-14Document Type DefinitionsDocument Type Definitions (DTDs) impose structure on XML documentsThere is some relationship between a DTD and a schema, but it is not close hence the need for additional “typing” systems exists. The DTD is a syntactic specificationT2-Lecture-5 Ahmed Mumtaz Mustehsan www.w3schools.com1-15Document Type DefinitionsA description of legal, valid data further contributes to the interoperability and efficiency of using XMLA single DTD ensures a common format for each XML document that references it.An application can use a standard DTD to verify that data that it receives from the outside world is valid.An XML document that conforms to the rules within a DTD is said to be valid document.If the XML document does not follow the rules contained within the DTD, a parser generates an error.T2-Lecture-5 Ahmed Mumtaz Mustehsan www.w3schools.com1-16MotivationA DTD adds syntactical requirements in addition to the well-formed requirement.It helps in eliminating errors when creating or editing XML documents.It clarifies the intended semantics.It simplifies the processing of XML documentsT2-Lecture-5 Ahmed Mumtaz Mustehsan www.w3schools.com1-17An ExampleIn an address book, where can a phone number appear?Under , under or under both?If we have to check for all possibilities, processing takes longer and it may not be clear to whom a phone belongs to?T2-Lecture-5 Ahmed Mumtaz Mustehsan www.w3schools.com1-18Example: An Address Book Homer Simpson Dr. H. Simpson 1234 Springwater Road Springfield USA, 98765 (321) 786 2543 (051) 786 2544 (051) 786 2544 homer@math.springfield.edu Mixed telephones and faxesAs manyas neededAs many address lines as needed (in order)At most one greetingExactly one nameT2-Lecture-5 Ahmed Mumtaz Mustehsan www.w3schools.com1-19Specifying the Structurename to specify a name elementgreet? to specify an optional (0 or 1) greet elementsname, greet? to specify a name followed by an optional greetaddr* to specify 0 or more address linestel | fax a tel or a fax element (tel | fax)* 0 or more repeats of tel or faxemail* 0 or more email elementsT2-Lecture-5 Ahmed Mumtaz Mustehsan www.w3schools.com1-20Specifying the Structure (cont’d)So the whole structure of a person entry is specified byname, greet?, addr*, (tel | fax)*, email*This is known as a regular expression T2-Lecture-5 Ahmed Mumtaz Mustehsan www.w3schools.com1-21Element Type Definitionfor each element type E, a declaration of the form: where P is a regular expression, i.e.,P ::= EMPTY | ANY | #PCDATA | E’ | P1, P2 | P1 | P2 | P? | P+ | P* E’: element typeP1 , P2: concatenationP1 | P2: disjunction P?: optionalP+: one or more occurrences P*: 0 or more occurrencesT2-Lecture-5 Ahmed Mumtaz Mustehsan www.w3schools.com1-22Summary of Regular ExpressionsA The tag (i.e., element) A occurse1,e2 The expression e1 followed by e2e* 0 or more occurrences of ee? Optional: 0 or 1 occurrencese+ 1 or more occurrencese1 | e2 either e1 or e2(e) groupingT2-Lecture-5 Ahmed Mumtaz Mustehsan www.w3schools.com1-23The Definition of an Element Consists of Exactly One of the FollowingA regular expression (as defined earlier)EMPTY means that the element has no contentANY means that content can be any mixture of PCDATA and elements defined in the DTDMixed content which is defined as described on the next slide :(#PCDATA)T2-Lecture-5 Ahmed Mumtaz Mustehsan www.w3schools.com1-24The Definition of Mixed ContentMixed content is described by a repeatable OR group (#PCDATA | element-name | )*Inside the group, no regular expressions ; just ement names#PCDATA must be first followed by 0 or more element names, separated by |* The group can be repeated 0 or more timesT2-Lecture-5 Ahmed Mumtaz Mustehsan www.w3schools.com1-25Some Example DTD DeclarationsExample 1: Elements with Data April This is a month JanMarch T2-Lecture-5 Ahmed Mumtaz Mustehsan www.w3schools.com1-26Some Example DTD DeclarationsExample 3: Elements with Children ;To specify that an element must have a single child element, include the element name within the parenthesis. 5 Park Road Chak Shahzad, Islamabad T2-Lecture-5 Ahmed Mumtaz Mustehsan www.w3schools.com1-27Some Example DTD DeclarationsExample-3: An element can have multiple children. A DTD describes multiple children using a sequence, or a list of elements separated by commas. The XML file must contain one of each element in the specified order. Tariq Rasheed 9th Eveneue. Federal Area, Islamabad 44000 T2-Lecture-5 Ahmed Mumtaz Mustehsan www.w3schools.com1-28Cautions concerning DTDsAll element declarations begin with The ELEMENT declaration is case sensitiveThe programmer must declare all elements within an XML fileElements declared with the #PCDATA content model can not have childrenWhen describing sequences, (e1,e2) the XML document must contain exactly those elements in exactly that order. T2-Lecture-5 Ahmed Mumtaz Mustehsan www.w3schools.com1-29An Address-Book XML Document with an Internal DTD ]>The name ofthe DTD is addressbook“Internal” means that the DTD and theXML Document are in the same file The syntax of a DTD is not XML syntaxT2-Lecture-5 Ahmed Mumtaz Mustehsan www.w3schools.com1-30The Address-Book XML Document Ahmed Mumtaz Prof. Mumtaz am@yahoo.com T2-Lecture-5 Ahmed Mumtaz Mustehsan www.w3schools.com1-31XML documents are similar to database filesExample:A Relational database for school:student: course: enroll:T2-Lecture-5 Ahmed Mumtaz Mustehsan www.w3schools.com1-32XML Representation of school database Joe 3.0 Mary 4.0 DB 3.0 Web 3.0 T2-Lecture-5 Ahmed Mumtaz Mustehsan www.w3schools.com1-33 001 331 001 350 002 331 XML Representation of school database T2-Lecture-5 Ahmed Mumtaz Mustehsan www.w3schools.com1-34Well-Formed XML DocumentsAn XML document (with or without a DTD) is well-formed ifTags are syntactically correctEvery tag has an end tagTags are properly nestedThere is a root tagA start tag does not have two occurrences of the same attributeAn XML document must be well formedT2-Lecture-5 Ahmed Mumtaz Mustehsan www.w3schools.com1-35Strengthen the data-modeling capabilities of XMLUsingXML SchemasWhat is an XML Schema?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 documentdefines attributes that can appear in a documentdefines which elements are child elementsdefines the order of child elementsdefines the number of child elementsdefines whether an element is empty or can include textdefines data types for elements and attributesdefines default and fixed values for elements and attributesT2-Lecture-5 Ahmed Mumtaz Mustehsan www.w3schools.com1-37XML Schemas are the Successors of DTDsIt is expected that XML Schemas will be used in most Web applications as a replacement for DTDs. Here are some reasons:XML Schemas are extensible to future additionsXML Schemas are richer and more powerful than DTDsXML Schemas are written in XMLXML Schemas support data typesXML Schemas support namespacesT2-Lecture-5 Ahmed Mumtaz Mustehsan www.w3schools.com1-38XML SchemaXML Schema is an XML-based alternative to DTD:Example:                     T2-Lecture-5 Ahmed Mumtaz Mustehsan www.w3schools.com1-39XML SchemaThe Schema in previous example is interpreted like this:Explanation of the Example: defines the element called "note" the "note" element is a complex type the complex type is a sequence of elements the element "to" is of type string (text) the element "from" is of type string the element "heading" is of type string the element "body" is of type stringEverything is wrapped in "Well Formed" XML.T2-Lecture-5 Ahmed Mumtaz Mustehsan www.w3schools.com1-40Why Use an XML Schema?With XML Schema, the XML files can carry a description of its own format.With XML Schema, independent groups of people can agree on a standard for interchanging data.T2-Lecture-5 Ahmed Mumtaz Mustehsan www.w3schools.com1-41XML Schemas use XML SyntaxAnother great strength about XML Schemas is that they are written in XML:You don't have to learn a new languageYou can use your XML editor to edit your Schema filesYou can use your XML parser to parse your Schema filesYou can manipulate your Schemas with the XML DOMYou can transform your Schemas with XSLTT2-Lecture-5 Ahmed Mumtaz Mustehsan www.w3schools.com1-42XML Schemas Support Data TypesOne of the greatest strength of XML Schemas is the support for data types:It is easier to describe document contentIt is easier to define restrictions on dataIt is easier to validate the correctness of dataIt is easier to convert data between different data typesT2-Lecture-5 Ahmed Mumtaz Mustehsan www.w3schools.com1-43XML Schemas Support Data TypesOne of the greatest strength of XML Schemas is the support for data types:It is easier to describe document contentIt is easier to define restrictions on dataIt is easier to validate the correctness of dataIt is easier to convert data between different data typesT2-Lecture-5 Ahmed Mumtaz Mustehsan www.w3schools.com1-44XML Schemas Secure Data CommunicationWhen sending data from a sender to a receiver, it is essential that both parts have the same "expectations" about the content.With XML Schemas, the sender can describe the data in a way that the receiver will understand.A date like: "03-11-2004" will, in some countries, be interpreted as 3.November and in other countries as 11.March.However, an XML element with a data type like this:2004-03-11ensures a mutual understanding of the content, because the XML data type "date" requires the format "YYYY-MM-DD".T2-Lecture-5 Ahmed Mumtaz Mustehsan www.w3schools.com1-45XML Schemas are ExtensibleXML Schemas are extensible, because they are written in XML. With an extensible Schema definition you can:Reuse your Schema in other SchemasCreate your own data types derived from the standard typesReference multiple schemas in the same documentT2-Lecture-5 Ahmed Mumtaz Mustehsan www.w3schools.com1-46Well-Formed is not EnoughA well-formed XML document is a document that conforms to the XML syntax rules, like:it must begin with the XML declarationit must have one unique root elementstart-tags must have matching end-tagselements are case sensitiveall elements must be closedall elements must be properly nestedall attribute values must be quotedentities must be used for special charactersT2-Lecture-5 Ahmed Mumtaz Mustehsan www.w3schools.com1-47The EndeXtensable Markup Language (XML) Part – IIIThank YouT2-Lecture-5 Ahmed Mumtaz Mustehsan www.w3schools.com1-48

Các file đính kèm theo tài liệu này:

  • pptt2_lecture_05_1302_2027094.ppt