Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Using XML. 2 The Ticket Booth System We need a way to retain information between program runs. In real life, we would probably use a database system.

Similar presentations


Presentation on theme: "1 Using XML. 2 The Ticket Booth System We need a way to retain information between program runs. In real life, we would probably use a database system."— Presentation transcript:

1 1 Using XML

2 2 The Ticket Booth System We need a way to retain information between program runs. In real life, we would probably use a database system for this. Beyond the scope of this course. We will use text files. XML text files. A widely used method of representing structured data in a plain text file.

3 3 XML Extensible Markup Language A metalanguage Language used to describe languages Using XML we can create a markup language for a specific purpose. Self describing. Text based System independent.

4 4 XML Like C++, XML is a big subject. Just a brief introduction in this course. But enough to do useful work.

5 5 The Little Theater 1234567 1234567 1234567 1234567 1234567 1234567 Row A Row B Row C Row D Row E Row F Front Section Back Section Left Section Right Section Center Section

6 6 Example: Venue.xml Download: http://www.cse.usf.edu/~turnerr/Object_Oriented_Design/ Downloads/2011_03_28_XML/Venue.xml http://www.cse.usf.edu/~turnerr/Object_Oriented_Design/ Downloads/2011_03_28_XML/Venue.xml Open in Visual Studio Or you can view the file in any browser.

7 7 Venue.xml in Visual Studio

8 8 Things to Notice First line Every xml file begins like this. The words in angle brackets are tags. Tags always come in matched pairs:... Every well formed xml file has a single root tag. in this case. Tags must be properly nested.

9 9 Things to Notice Everything between a start tag and its matching end tag is information about an object identified by the start tag. Compare to aggregation in UML. "Has a" relationship. "Is a part of" In Visual Studio, and other xml aware editors, we can collapse or expand the tags. There can be multiple instances of a tag name....

10 10 XML Tag Names Tag names are similar to variable names in C++. Tag names are case sensitive. Cannot contain spaces, punctuation, etc. Letters, digits, and the underscore character. First character cannot be a digit.

11 11 Comments XML files can include comments Same as HTML Comments can extend over multiple lines.

12 12 Describing a Seat Row A seat_row consists of an arbitrary number of seats. Each seat has A row name A number A section name

13 13 Seat Row

14 14 Seating Sections We could define tags for seating sections. Show the section information separately from the seat row definitions. It is more convenient to include the section name in the element.

15 15 Using XML in a Program We can write code to output objects to an XML file. Similar to a Display method. Save objects on disk between program runs. Serialization. Likewise, we can create objects using information read from an XML file. Deserialization Need an XML parser.

16 16 More Objects in XML Download and examine the other XML files in the Downloads area: http://www.cse.usf.edu/~turnerr/Object_Oriented_Design/Downloads/ 2011_03_28_XML http://www.cse.usf.edu/~turnerr/Object_Oriented_Design/Downloads/ 2011_03_28_XML Ticket.xml Show.xml Booking.xml

17 17 A Ticket in XML

18 18 A Show in XML

19 19 A Booking in XML

20 20 Booking (continued)

21 21 Class Activity What will be the price of a ticket for seat B4 for the performance of the Music Man at the Little Theater on Dec. 2, 2010?

22 22 Answer $95 Venue Seat B4 is in the Center section. Booking The Center section will have price level 1 Dec. 2 will have the Normal price schedule. Show In the Normal price schedule, level 1 is $95


Download ppt "1 Using XML. 2 The Ticket Booth System We need a way to retain information between program runs. In real life, we would probably use a database system."

Similar presentations


Ads by Google