XML Documents 5 May 2016 OSU CSE 1 e X tensible M arkup L anguage - - PowerPoint PPT Presentation

xml documents
SMART_READER_LITE
LIVE PREVIEW

XML Documents 5 May 2016 OSU CSE 1 e X tensible M arkup L anguage - - PowerPoint PPT Presentation

XML Documents 5 May 2016 OSU CSE 1 e X tensible M arkup L anguage A textual document format used all over the web is XML Used to represent hierarchically organized data for ease of use both by humans and computers Had its


slide-1
SLIDE 1

XML Documents

5 May 2016 OSU CSE 1

slide-2
SLIDE 2

eXtensible Markup Language

  • A textual document format used all over

the web is XML

– Used to represent hierarchically organized data for “ease of use” both by humans and computers – Had its origins in SGML (Standard Generalized Markup Language) from the 1980s – Became a standard in the late 1990s

5 May 2016 OSU CSE 2

slide-3
SLIDE 3

Example XML Document/File

<?xml version="1.0" encoding="UTF-8"?> <book printISBN="978-1-118-06331-6" webISBN="1-118063-31-7" pubDate="Dec 20 2011"> <author>Cay Horstmann</author> <title> Java for Everyone: Late Objects </title> ... </book>

5 May 2016 OSU CSE 3

slide-4
SLIDE 4

Example XML Document/File

<?xml version="1.0" encoding="UTF-8"?> <book printISBN="978-1-118-06331-6" webISBN="1-118063-31-7" pubDate="Dec 20 2011"> <author>Cay Horstmann</author> <title> Java for Everyone: Late Objects </title> ... </book>

5 May 2016 OSU CSE 4

An XML declaration is the first line of well- formed XML file.

slide-5
SLIDE 5

Example XML Document/File

<?xml version="1.0" encoding="UTF-8"?> <book printISBN="978-1-118-06331-6" webISBN="1-118063-31-7" pubDate="Dec 20 2011"> <author>Cay Horstmann</author> <title> Java for Everyone: Late Objects </title> ... </book>

5 May 2016 OSU CSE 5

This is not part of the actual document/file!

slide-6
SLIDE 6

Example XML Document/File

<?xml version="1.0" encoding="UTF-8"?> <book printISBN="978-1-118-06331-6" webISBN="1-118063-31-7" pubDate="Dec 20 2011"> <author>Cay Horstmann</author> <title> Java for Everyone: Late Objects </title> ... </book>

5 May 2016 OSU CSE 6

This is an author element.

slide-7
SLIDE 7

Example XML Document/File

<?xml version="1.0" encoding="UTF-8"?> <book printISBN="978-1-118-06331-6" webISBN="1-118063-31-7" pubDate="Dec 20 2011"> <author>Cay Horstmann</author> <title> Java for Everyone: Late Objects </title> ... </book>

5 May 2016 OSU CSE 7

This is a start tag for an author element.

slide-8
SLIDE 8

Example XML Document/File

<?xml version="1.0" encoding="UTF-8"?> <book printISBN="978-1-118-06331-6" webISBN="1-118063-31-7" pubDate="Dec 20 2011"> <author>Cay Horstmann</author> <title> Java for Everyone: Late Objects </title> ... </book>

5 May 2016 OSU CSE 8

This is an end tag for that author element.

slide-9
SLIDE 9

Example XML Document/File

<?xml version="1.0" encoding="UTF-8"?> <book printISBN="978-1-118-06331-6" webISBN="1-118063-31-7" pubDate="Dec 20 2011"> <author>Cay Horstmann</author> <title> Java for Everyone: Late Objects </title> ... </book>

5 May 2016 OSU CSE 9

The content for this author element is everything between its start and end tags.

slide-10
SLIDE 10

Example XML Document/File

<?xml version="1.0" encoding="UTF-8"?> <book printISBN="978-1-118-06331-6" webISBN="1-118063-31-7" pubDate="Dec 20 2011"> <author></author> <title> Java for Everyone: Late Objects </title> ... </book>

5 May 2016 OSU CSE 10

If the author element had no content, then you might find this, or…

slide-11
SLIDE 11

Example XML Document/File

<?xml version="1.0" encoding="UTF-8"?> <book printISBN="978-1-118-06331-6" webISBN="1-118063-31-7" pubDate="Dec 20 2011"> <author /> <title> Java for Everyone: Late Objects </title> ... </book>

5 May 2016 OSU CSE 11

… or you might find a single self-closing tag like this.

slide-12
SLIDE 12

Example XML Document/File

<?xml version="1.0" encoding="UTF-8"?> <book printISBN="978-1-118-06331-6" webISBN="1-118063-31-7" pubDate="Dec 20 2011"> <author>Cay Horstmann</author> <title> Java for Everyone: Late Objects </title> ... </book>

5 May 2016 OSU CSE 12

This is a title element.

slide-13
SLIDE 13

Example XML Document/File

<?xml version="1.0" encoding="UTF-8"?> <book printISBN="978-1-118-06331-6" webISBN="1-118063-31-7" pubDate="Dec 20 2011"> <author>Cay Horstmann</author> <title> Java for Everyone: Late Objects </title> ... </book>

5 May 2016 OSU CSE 13

This is a book element.

slide-14
SLIDE 14

Example XML Document/File

<?xml version="1.0" encoding="UTF-8"?> <book printISBN="978-1-118-06331-6" webISBN="1-118063-31-7" pubDate="Dec 20 2011"> <author>Cay Horstmann</author> <title> Java for Everyone: Late Objects </title> ... </book>

5 May 2016 OSU CSE 14

This is the name of an attribute

  • f the book

element.

slide-15
SLIDE 15

Example XML Document/File

<?xml version="1.0" encoding="UTF-8"?> <book printISBN="978-1-118-06331-6" webISBN="1-118063-31-7" pubDate="Dec 20 2011"> <author>Cay Horstmann</author> <title> Java for Everyone: Late Objects </title> ... </book>

5 May 2016 OSU CSE 15

This is the value

  • f the

printISBN attribute.

slide-16
SLIDE 16

Recursive Structure

  • An XML document (without the XML

declaration in the first line) is made up of:

– A top-level element – A string of zero or more child elements of the top-level element, each of which is exactly like the top-level element of an XML document

  • Notice the similarity to a tree: the structure
  • f an XML document is also recursive
  • Information it represents is hierarchical

5 May 2016 OSU CSE 16

slide-17
SLIDE 17

Can You Find All The Errors?

<?xml version="1.0" encoding="UTF-8"?> <pony> <unicorn mark="three lozenges"> <color>cyan</unicorn> </color> <unicorn>Twilight<color>cyan</color>Sparkle</unicorn> <unicorn mark="dolphins" version="G4" /> </pony> <dragon> <youth>Spike </dragon>

5 May 2016 OSU CSE 17

slide-18
SLIDE 18

Resources

  • Big Java, Section 23.1 (but not the rest of

Chapter 23)

– https://library.ohio-state.edu/record=b8540788~S7

  • Wikipedia: XML

– http://en.wikipedia.org/wiki/XML

5 May 2016 OSU CSE 18