Presentation is loading. Please wait.

Presentation is loading. Please wait.

Representing data with XML SE-2030 Dr. Mark L. Hornick 1.

Similar presentations


Presentation on theme: "Representing data with XML SE-2030 Dr. Mark L. Hornick 1."— Presentation transcript:

1 Representing data with XML SE-2030 Dr. Mark L. Hornick 1

2 XML: EXtensible Markup Language XML is a technology for defining markup languages to represent data designed to define structured data descriptions that are Extensible/customizable Portable across languages, Portable across operating system platforms SE-2030 Dr. Mark L. Hornick 2

3 3 XML allows you to define your own markup language You can define your own tags Tag vocabulary XML can use an optional DTD (Document Type Definition) or XSD (XML Schema Defn) to formally describe the data How tags can nest What attributes a tag can/must have i.e. tag grammar Data that is described by a specified vocabulary & grammar is called an XML Application

4 SE-2030 Dr. Mark L. Hornick 4 HTML is an XML application HTML is a description of data in web page documents, and how it is structured My web page HTML syntax summary or, all you need to know about HTML This is how you write an HTML document. The end.

5 SE-2030 Dr. Mark L. Hornick 5 XML schemas define how HTML can be structured (for instance, a can appear within a, but not within a ) html h1 head body strong p title p em p strong

6 SE-2030 Dr. Mark L. Hornick 6 What else is XML good for? XML can be used as a format for storing data in files in a structured manner Separating content from presentation, so that data created by an application written in Java can be read by an application written in C (or Javascript, or any other language)

7 Scenario Consider a Java collection of Students: List students; where public class Student { String firstname; String lastname; int id; String program; } SE-2030 Dr. Mark L. Hornick 7

8 In Java, we can use serialization to write/store students to a file, to be read (later) by another Java application Provided the other Java application knows the definition of Student and List It would be much more difficult for a program written in C or JavaScript to read the file Further complications arise when the file is read by an application running on another HW or OS platform SE-2030 Dr. Mark L. Hornick 8

9 XML allows us to create a document that can be used to represent a portable collection of Students: Bored Bill 1111 SE Bob Sledd 1112 CE SE-2030 Dr. Mark L. Hornick 9 XML grammars (like the one here) represent all data in plain text, which is most easily interpreted across platforms

10 The XML grammar itself may be defined by an optional XML Schema Definition (or a Document Type Defintion/DTD) SE-2030 Dr. Mark L. Hornick 10 XML Schema Definitions (like the one here) define the valid format of the XML data. For instance the tag specifies that the firstname…program tags MUST appear in only that sequence

11 Here is another XML document that can be used to represent a portable collection of Students: <student firstname=“Bill” lastname=“Bored” id=“1111” program=“SE” <student firstname=“Bob” lastname=“Sledd” id=“1114” program=“CE” SE-2030 Dr. Mark L. Hornick 11 Note that this grammar defines firstname…program as attributes instead of child elements

12 The XML Schema Definition for the alternate grammar: SE-2030 Dr. Mark L. Hornick 12

13 How do you read the data from an XML document? Most languages implement XML Parsers that can interpret an XML file and extract the data XML Parsers can be “told” to use the optional XML Schema to ensure that the XML file being parsed is in a valid format Validation is optional; you can create XML files without creating an XML Schema, but then you have no way of constraining the syntax SE-2030 Dr. Mark L. Hornick 13

14 XML Parser Demonstration SE-2030 Dr. Mark L. Hornick 14


Download ppt "Representing data with XML SE-2030 Dr. Mark L. Hornick 1."

Similar presentations


Ads by Google