Top Banner
XML Documents 5 May 2016 OSU CSE 1
18

CSE 2221 - XML Documentsweb.cse.ohio-state.edu/.../web-sw1/extras/slides/11.XML-Documents.pdf · Cay Horstmann Java for Everyone: Late Objects

Feb 16, 2019

Download

Documents

LêHạnh
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: CSE 2221 - XML Documentsweb.cse.ohio-state.edu/.../web-sw1/extras/slides/11.XML-Documents.pdf · <author>Cay Horstmann</author> <title> Java for Everyone: Late Objects

XML Documents

5 May 2016 OSU CSE 1

Page 2: CSE 2221 - XML Documentsweb.cse.ohio-state.edu/.../web-sw1/extras/slides/11.XML-Documents.pdf · <author>Cay Horstmann</author> <title> Java for Everyone: Late Objects

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

Page 3: CSE 2221 - XML Documentsweb.cse.ohio-state.edu/.../web-sw1/extras/slides/11.XML-Documents.pdf · <author>Cay Horstmann</author> <title> Java for Everyone: Late Objects

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

Page 4: CSE 2221 - XML Documentsweb.cse.ohio-state.edu/.../web-sw1/extras/slides/11.XML-Documents.pdf · <author>Cay Horstmann</author> <title> Java for Everyone: Late Objects

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.

Page 5: CSE 2221 - XML Documentsweb.cse.ohio-state.edu/.../web-sw1/extras/slides/11.XML-Documents.pdf · <author>Cay Horstmann</author> <title> Java for Everyone: Late Objects

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!

Page 6: CSE 2221 - XML Documentsweb.cse.ohio-state.edu/.../web-sw1/extras/slides/11.XML-Documents.pdf · <author>Cay Horstmann</author> <title> Java for Everyone: Late Objects

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 authorelement.

Page 7: CSE 2221 - XML Documentsweb.cse.ohio-state.edu/.../web-sw1/extras/slides/11.XML-Documents.pdf · <author>Cay Horstmann</author> <title> Java for Everyone: Late Objects

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 astart tag

for an authorelement.

Page 8: CSE 2221 - XML Documentsweb.cse.ohio-state.edu/.../web-sw1/extras/slides/11.XML-Documents.pdf · <author>Cay Horstmann</author> <title> Java for Everyone: Late Objects

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 anend tag

for that authorelement.

Page 9: CSE 2221 - XML Documentsweb.cse.ohio-state.edu/.../web-sw1/extras/slides/11.XML-Documents.pdf · <author>Cay Horstmann</author> <title> Java for Everyone: Late Objects

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 contentfor this author

element is everything between its start and

end tags.

Page 10: CSE 2221 - XML Documentsweb.cse.ohio-state.edu/.../web-sw1/extras/slides/11.XML-Documents.pdf · <author>Cay Horstmann</author> <title> Java for Everyone: Late Objects

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 authorelement had no

content, then you might find this, or…

Page 11: CSE 2221 - XML Documentsweb.cse.ohio-state.edu/.../web-sw1/extras/slides/11.XML-Documents.pdf · <author>Cay Horstmann</author> <title> Java for Everyone: Late Objects

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 taglike this.

Page 12: CSE 2221 - XML Documentsweb.cse.ohio-state.edu/.../web-sw1/extras/slides/11.XML-Documents.pdf · <author>Cay Horstmann</author> <title> Java for Everyone: Late Objects

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.

Page 13: CSE 2221 - XML Documentsweb.cse.ohio-state.edu/.../web-sw1/extras/slides/11.XML-Documents.pdf · <author>Cay Horstmann</author> <title> Java for Everyone: Late Objects

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 abook

element.

Page 14: CSE 2221 - XML Documentsweb.cse.ohio-state.edu/.../web-sw1/extras/slides/11.XML-Documents.pdf · <author>Cay Horstmann</author> <title> Java for Everyone: Late Objects

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

attributeof the book

element.

Page 15: CSE 2221 - XML Documentsweb.cse.ohio-state.edu/.../web-sw1/extras/slides/11.XML-Documents.pdf · <author>Cay Horstmann</author> <title> Java for Everyone: Late Objects

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 valueof the

printISBNattribute.

Page 16: CSE 2221 - XML Documentsweb.cse.ohio-state.edu/.../web-sw1/extras/slides/11.XML-Documents.pdf · <author>Cay Horstmann</author> <title> Java for Everyone: Late Objects

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 of an XML document is also recursive

• Information it represents is hierarchical5 May 2016 OSU CSE 16

Page 17: CSE 2221 - XML Documentsweb.cse.ohio-state.edu/.../web-sw1/extras/slides/11.XML-Documents.pdf · <author>Cay Horstmann</author> <title> Java for Everyone: Late Objects

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

Page 18: CSE 2221 - XML Documentsweb.cse.ohio-state.edu/.../web-sw1/extras/slides/11.XML-Documents.pdf · <author>Cay Horstmann</author> <title> Java for Everyone: Late Objects

Resources• Big Java Late Objects, Section 23.1 (but not the

rest of Chapter 23)– http://proquest.safaribooksonline.com.proxy.lib.ohio-

state.edu/book/programming/java/9781118087886/chapter-23-xml/navpoint-172

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

5 May 2016 OSU CSE 18