Presentation is loading. Please wait.

Presentation is loading. Please wait.

ICS 123 XML: It’s a Good Thing Richard N. Taylor & Eric M. Dashofy ICS 123 S2002.

Similar presentations


Presentation on theme: "ICS 123 XML: It’s a Good Thing Richard N. Taylor & Eric M. Dashofy ICS 123 S2002."— Presentation transcript:

1 ICS 123 XML: It’s a Good Thing Richard N. Taylor & Eric M. Dashofy ICS 123 S2002

2 ICS 123 2 Topic 10 XML Motivation “I'll never go hungry again!” –Scarlett O’Hara “I’ll never write a parser again!” – Anonymous XML User Data encoding is a perpetual problem in computer applications Lots of time is wasted writing parsers, lexers, marshalers, unmarshalers, data bindings, even meta-languages!

3 ICS 123 3 Topic 10 XML Existing Problems App2 App3 App1 File Format 2 File Format 3 File Format 1 Import Converter Export Converter 3 rd Party Converter File Exchange

4 ICS 123 4 Topic 10 XML Why is this a problem? Everybody has a proprietary format Converters must be maintained by various parties –This is an n 2 problem! Something is usually lost in the translation Note: Same problems with data exchange across networked apps

5 ICS 123 5 Topic 10 XML Another Problem Defining a File or Data Format Parser In-memory Representation Disk Net Meta- Language Helps to generate Serializer Data Bindings Helps to generate edits

6 ICS 123 6 Topic 10 XML Why is this a problem? Parsers, serializers, data bindings all have to be developed This development takes time Conflicting tools for assistance How do you evolve the file format?

7 ICS 123 7 Topic 10 XML Potential Solution To too many file formats: –Intermediate format »Even better: Common format –An agreed-upon meta-language –Ability to extend language and ignore unknown constructs To tool-building: –Choose a suitable meta-language –Build tools surrounding that meta-language –Port those tools to different environments, but keep the APIs semi- standard

8 ICS 123 8 Topic 10 XML What is XML Stolen from xml-computing.com: –eXtensible Markup Language –A way to represent structured data –a World Wide Web Consortium (W3C) standard –platform-independent –a way to create your own custom languages –license-free and well-supported –the future of computing? Buzzword-compliant!

9 ICS 123 9 Topic 10 XML Origins of XML From SGML –Standard Generalized Markup Language cf. HTML A document markup language –For annotating documents with metadata to make them easier to interpret Hi! My name is Eric Dashofy. You can email me at edashofy@ics.uci.edu.

10 ICS 123 10 Topic 10 XML The Times, They are a Changin’ XML is arguably more useful to simply encode data, outside the strict context of a document Eric Dashofy Information and Computer Science edashofy@ics.uci.edu

11 ICS 123 11 Topic 10 XML Terminology Tag –The markup of the document, enclosed in angle-brackets. » is the start tag » is the end tag –Tags may be nested, but may not cross » foo bar baz --OK! » foo bar baz --NO! –Hierarchical data structure

12 ICS 123 12 Topic 10 XML Terminology Element –Stuff in between a start and end tag –Includes the tags –May contain nested elements –Ex: » foo » foo bar (nested)

13 ICS 123 13 Topic 10 XML Terminology Attribute –A way of annotating tags with additional info –Simple name-value pairs –Ex: » Henry » Enrique

14 ICS 123 14 Topic 10 XML Document A collection of elements, usually in a file One top-level element –Called the “root” element or “document” element –Some header stuff Eric Dashofy Information and Computer Science edashofy@ics.uci.edu

15 ICS 123 15 Topic 10 XML Side-note: “If you don’t understand it, ignore it.”

16 ICS 123 16 Topic 10 XML Kinds of Documents “Well Formed” –Syntactically correct –All the start tags have end tags –All the start-quotes have end-quotes –etc. “Valid” –Well-formed, and conforms to some language specification

17 ICS 123 17 Topic 10 XML Why a meta-language? To define what elements, sub-elements, attributes are allowed And in what order So different organizations can agree on a real data format –Well-formed documents don’t restrict how you encode the data, so they’re not very valuable

18 ICS 123 18 Topic 10 XML DTDs Document Type Definition –Part of XML 1.0 –The original XML meta-language –Doesn’t look like XML –Like production rules ]>

19 ICS 123 19 Topic 10 XML Namespaces “You keep on using that word, I do not think it means what you think it means.” –Inigo Montoya How can you make a document that draws elements from multiple DTDs? 1600 Pennsylvania Ave Washington DC 20509 23B Baker Street London, England N22

20 ICS 123 20 Topic 10 XML Why not DTDs? “Uhm, DTDs are bad, mmkay?” –Mr. Mackey –DTDs are lacking in some areas »Don’t look like XML »Can’t specify at a level below elements i.e. can’t specify regular expressions on content »Difficult to extend/add things to existing element definitions »Difficult to implement modular languages

21 ICS 123 21 Topic 10 XML XML Schemas A DTD replacement from W3C –Look like XML / Easier to read –Contribute a type system to XML –Element, attribute definitions become types »Single-inheritance model in the type system –Better namespace management

22 ICS 123 22 Topic 10 XML Example

23 ICS 123 23 Topic 10 XML Example, cont.

24 ICS 123 24 Topic 10 XML What do you get? Lots of tools for free –Parsers »DOM and SAX –Serializers –Transformation »XSL(T) –A meta-language (two, actually ) –Data Bindings –Syntax-directed editors

25 ICS 123 25 Topic 10 XML Spotlight: DOM & SAX APIs for accessing XML documents –SAX: Lightweight, callback based »“I saw an element! Ooh, I saw an attribute!” –DOM: Parses entire document into an object tree in memory In-memory Representation XML Document DOM Parser

26 ICS 123 26 Topic 10 XML Spotlight: Data Bindings DOM API is very, very generic –Example functions: »appendChild(Element n) »setAttribute(String name, String value) –No namespace management Data bindings are APIs guided by the language definition –Example functions: »addComponent(Component c); »setIdentifier(String id); Data bindings can be generated automatically


Download ppt "ICS 123 XML: It’s a Good Thing Richard N. Taylor & Eric M. Dashofy ICS 123 S2002."

Similar presentations


Ads by Google