Presentation is loading. Please wait.

Presentation is loading. Please wait.

VICTORIA UNIVERSITY OF WELLINGTON Te Whare Wananga o te Upoko o te Ika a Maui SWEN 432 Advanced Database Design and Implementation An Introduction to XML.

Similar presentations


Presentation on theme: "VICTORIA UNIVERSITY OF WELLINGTON Te Whare Wananga o te Upoko o te Ika a Maui SWEN 432 Advanced Database Design and Implementation An Introduction to XML."— Presentation transcript:

1 VICTORIA UNIVERSITY OF WELLINGTON Te Whare Wananga o te Upoko o te Ika a Maui SWEN 432 Advanced Database Design and Implementation An Introduction to XML Lecturer : Dr. Pavle Mogin

2 SWEN 432 Advanced Database Design and Implementation 2015 Intro to XML 1 Plan for The Introduction into XML Answering the question “Why XML” XML concepts: –Processing instructions and the XML declaration –Elements, –Attributes, –Empty tags, –Comments, –Entity references, and –CDATA section –Well Formed Documents –Reading: W3C Recommendations at http://www.w3c.org/TR/http://www.w3c.org/TR/ Ramakrishnan, Gherke: Database Management Systems, Chapter 7 and Chapter 27 Any book on XML

3 SWEN 432 Advanced Database Design and Implementation 2015 Intro to XML 2 The Main Motive The main motive for introducing XML was to enable a seamless flow of data between parties communicating over Internet –HTML proved to be inadequate, since its tags embed document presentation information, only, –XML tags imbed both structuring rules and meaning of data A valid sample of XML code: NZD 99.95

4 SWEN 432 Advanced Database Design and Implementation 2015 Intro to XML 3 Origin of XML XML has been completed in early 1998 by W3C –The same organization that is setting the overall directions for the Web XML defines an open and flexible standard for: –Defining new languages, –Publishing, and –Exchanging any kind of information Soon, after it introduction, people realized that they need not only to exchange data, but also to: –Store, –Query, –Update, –Protect … Hence, database behaviour

5 SWEN 432 Advanced Database Design and Implementation 2015 Intro to XML 4 XML Meta Languages New XML languages are defined using XML meta languages XML meta languages consist of official words, rules and conventions (grammar) that allow: –Creation of an own corporate or industry standard markup language, –Including data structuring and semantic rules into the new language, –Easy understanding by communicating parties XML meta languages are used to design XML schemes

6 SWEN 432 Advanced Database Design and Implementation 2015 Intro to XML 5 Related Technologies Style languages (to define appearence): –Cascading Style Sheets (CSS), –Extensible Style Language (XSL) Supplemental Technologies: –XLinks, –XPointers, –Namespaces, and –Resource Description Framework

7 SWEN 432 Advanced Database Design and Implementation 2015 Intro to XML 6 XML Declaration XML documents may be recognized by the XML declaration This is a processing instruction placed at the start of an XML file (= document) that identifies the version in use An XML document may have more than one processing instruction, Here are two processing instructions:

8 SWEN 432 Advanced Database Design and Implementation 2015 Intro to XML 7 XML Elements Elements are XML basic building blocks Each element has a start and an end tag Content A tag contains an element’s name and carries semantics of the element content An element name must be a valid XML name: –Should start with a letter or an underscore, –Subsequent characters may include letters, digits, underscores, hyphens, and periods –May not include whitespace

9 SWEN 432 Advanced Database Design and Implementation 2015 Intro to XML 8 Content of an Element and the Root The content of an element may be some text or other elements James Bond Each XML document has exactly one root element A root element contains all other elements of a document as its content Elements that appear inside another element can have more than one instance inside the same document

10 SWEN 432 Advanced Database Design and Implementation 2015 Intro to XML 9 Some Basic Structuring Rules Elements can be nested inside elements Content Elements must be properly nested –The start tag that appears inside the content of another tag must have an end tag inside the same parent element –That way hierarchical structures are built Text may be interspersed with elements text Unlike HTML, XML tags are case sensitive

11 SWEN 432 Advanced Database Design and Implementation 2015 Intro to XML 10 An XML Fragment Ahmed Craig

12 SWEN 432 Advanced Database Design and Implementation 2015 Intro to XML 11 Attributes An attribute is a (name, value) pair Both name and value are strings that are separated by “=” Attributes are set inside: –A processing instruction –The start tag of an element All attribute values must be enclosed in quotation marks Attribute names must be valid XML names No element or processing instruction may have two attributes with the same name

13 SWEN 432 Advanced Database Design and Implementation 2015 Intro to XML 12 An XML Fragment with Attributes Ahmed Craig

14 SWEN 432 Advanced Database Design and Implementation 2015 Intro to XML 13 The same XML Data with Elements SWEN432 31 39.0 Ahmed …

15 SWEN 432 Advanced Database Design and Implementation 2015 Intro to XML 14 Empty Tags If an element is not going to have any content (except possibly attributes) it does not need to have a start and an end tag, but an empty tag only Empty tags may contain attributes and usually do

16 SWEN 432 Advanced Database Design and Implementation 2015 Intro to XML 15 Comments Similar to HTML, XML comments start with “ ” Comments may be inserted anywhere in an XML document, but not: –Before the document declaration, or –Inside a tag Everyone likes this comment: But, all data between comment tags are ignored by browsers

17 SWEN 432 Advanced Database Design and Implementation 2015 Intro to XML 16 Entity References Entity references are markup that is replaced with character data when the document is parsed A browser parses an XML document before it renders it Wherever an entity reference appears in an XML document, it is textually replaced by its content Entity references start with a ‘&’ and end with a ‘ ; ’ There are five predefined entities: –< is represented by & lt; –& is represented by & amp; –> is represented by & gt; –“ is represented by & quot ; and –‘ is represented by & apos;

18 SWEN 432 Advanced Database Design and Implementation 2015 Intro to XML 17 CDATA Section CDATA sections are used when you want all text to be interpreted as pure character rather than as markup This is particularly useful for text that contains a lot of, &, or “ characters but no markup A good example is a Java program CDATA section begins with <![CDATA[ and ends with ]]> All between “ [ “ and “ ]] ” is treated as a pure text

19 SWEN 432 Advanced Database Design and Implementation 2015 Intro to XML 18 Well Formed XML Documents XML browsers will render an XML document only if it is well formed A standalone XML document is well formed if: 1.It starts with an XML declaration, 2.It contains a root element that embeds all other elements, 3.All elements are properly nested, 4.Elements that contain other elements or text have both start and end tag, 5.Elements that do not contain other elements and text use only a single tag that ends with “/>”, 6.Attribute values are quoted, 7.The characters “<” and “&” are only used to start tags and entity references, respectively, 8.The only entity references which appear are &, <, >, &apos;, and " 9.Element and attribute names must be valid XML names

20 SWEN 432 Advanced Database Design and Implementation 2015 Intro to XML 19 Summary XML is an open and free standard that promotes exchange of documents via Internet An XML document: –Has a meaning that people understand easily, –May be easily processed by computers, –Is a tree structure over a set of: Elements, Attributes, Character data, Comments, and CDATA sections –Has a declaration at the beginning –Should be well formed


Download ppt "VICTORIA UNIVERSITY OF WELLINGTON Te Whare Wananga o te Upoko o te Ika a Maui SWEN 432 Advanced Database Design and Implementation An Introduction to XML."

Similar presentations


Ads by Google