XMLTree Model 5 May 2016 OSU CSE 1 XMLTree The XMLTree component - - PowerPoint PPT Presentation

xmltree model
SMART_READER_LITE
LIVE PREVIEW

XMLTree Model 5 May 2016 OSU CSE 1 XMLTree The XMLTree component - - PowerPoint PPT Presentation

XMLTree Model 5 May 2016 OSU CSE 1 XMLTree The XMLTree component family allows you to create, and navigate through, a tree whose structure mirrors that of an XML file The file from which the tree is created may come from your


slide-1
SLIDE 1

XMLTree Model

5 May 2016 OSU CSE 1

slide-2
SLIDE 2

XMLTree

  • The XMLTree component family allows

you to create, and navigate through, a tree whose structure mirrors that of an XML file

– The file from which the tree is created may come from your computer or from the web – You need not worry about parsing the file (recognizing tags, matching start-end tags, identifying attributes, etc.), as this is done for you by XMLTree

5 May 2016 OSU CSE 2

slide-3
SLIDE 3

Example XML File

<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> <contents> <preface></preface> <chapter number="1" title="Introduction"> <section title="Chapter Goals"></section> <section title="Chapter Contents"></section> <section title="Computer Programs" number="1.1"></section> <section title="The Anatomy of a Computer" number="1.2"></section> ... </chapter> <chapter number="2" title="Fundamental Data Types"> </chapter> ... </contents> </book>

5 May 2016 OSU CSE 3

slide-4
SLIDE 4

Example XMLTree Created

7 January 2019 OSU CSE 4

<book> printISBN → 978-1-118-06331-6 webISBN → 1-118063-31-7 pubDate → Dec 20 2011 <author> <title> <contents> Cay Horstmann Java for Everyone: Late Objects <preface> <chapter> number → 1 title → Introduction <chapter> number → 2 title → Fundamental Data Types <section> title → Chapter Goals <section> title → Chapter Contents <section> number → 1.1 title → Computer Programs <section> number → 1.2 title → The Anatomy of a Computer

. . . . . .

<book> <author> <title> <contents> <preface> <chapter> <chapter> <section> <section> <section> <section>

slide-5
SLIDE 5

Top-Level Element = Root of Tree

<book printISBN="978-1-118-06331-6" webISBN="1-118063-31-7" pubDate="Dec 20 2011"> ... </book>

7 January 2019 OSU CSE 5

slide-6
SLIDE 6

Top-Level Element = Root of Tree

<book printISBN="978-1-118-06331-6" webISBN="1-118063-31-7" pubDate="Dec 20 2011"> ... </book>

5 May 2016 OSU CSE 6

slide-7
SLIDE 7

<book printISBN="978-1-118-06331-6" webISBN="1-118063-31-7" pubDate="Dec 20 2011"> ... </book>

5 May 2016 OSU CSE 7

Top-Level Element = Root of Tree

slide-8
SLIDE 8

<book printISBN="978-1-118-06331-6" webISBN="1-118063-31-7" pubDate="Dec 20 2011"> ... </book>

5 May 2016 OSU CSE 8

Top-Level Element = Root of Tree

The attribute name-value pairs of an element/tag are in the tree node of that element/tag.

slide-9
SLIDE 9

<book printISBN="978-1-118-06331-6" webISBN="1-118063-31-7" pubDate="Dec 20 2011"> ... </book>

5 May 2016 OSU CSE 9

Top-Level Element = Root of Tree

slide-10
SLIDE 10

<book printISBN="978-1-118-06331-6" webISBN="1-118063-31-7" pubDate="Dec 20 2011"> ... </book>

5 May 2016 OSU CSE 10

Top-Level Element = Root of Tree

The children of the top-level element/tag are the children of the root of the tree.

slide-11
SLIDE 11

<book printISBN="978-1-118-06331-6" webISBN="1-118063-31-7" pubDate="Dec 20 2011"> ... </book>

5 May 2016 OSU CSE 11

Top-Level Element = Root of Tree

The first child node of the root is known as “child 0” because children are numbered from 0.

slide-12
SLIDE 12

<book printISBN="978-1-118-06331-6" webISBN="1-118063-31-7" pubDate="Dec 20 2011"> ... </book>

5 May 2016 OSU CSE 12

Top-Level Element = Root of Tree

The second child node

  • f the root is known as

“child 1”.

slide-13
SLIDE 13

<book printISBN="978-1-118-06331-6" webISBN="1-118063-31-7" pubDate="Dec 20 2011"> ... </book>

5 May 2016 OSU CSE 13

Top-Level Element = Root of Tree

The third child node of the root is known as “child 2”.

slide-14
SLIDE 14

First Child Element = First Child Node

<book ...> <author>Cay Horstmann</author> ... </book>

7 January 2019 OSU CSE 14

slide-15
SLIDE 15

<book ...> <author>Cay Horstmann</author> ... </book>

5 May 2016 OSU CSE 15

First Child Element = First Child Node

slide-16
SLIDE 16

<book ...> <author>Cay Horstmann</author> ... </book>

5 May 2016 OSU CSE 16

First Child Element = First Child Node

slide-17
SLIDE 17

<book ...> <author>Cay Horstmann</author> ... </book>

5 May 2016 OSU CSE 17

The content of an element/tag is in a child node of the node for that element/tag; the content node itself has no tag.

First Child Element = First Child Node

slide-18
SLIDE 18

<book ...> ...

<title>Java for Everyone: Late Objects</title>

... </book>

5 May 2016 OSU CSE 18

Second Child Element = Second Child Node

slide-19
SLIDE 19

<book ...> ...

<title>Java for Everyone: Late Objects</title>

... </book>

5 May 2016 OSU CSE 19

Second Child Element = Second Child Node

slide-20
SLIDE 20

<book ...> ...

<title>Java for Everyone: Late Objects</title>

... </book>

5 May 2016 OSU CSE 20

Second Child Element = Second Child Node

slide-21
SLIDE 21

… And So On!

  • The same rules apply at all levels of the

XML file and of the XMLTree object that is created from it

5 May 2016 OSU CSE 21

slide-22
SLIDE 22

Key Properties/Invariants

  • Every node in the tree represents either a tag

(e.g., <author>) or the text content (e.g., "Cay Horstman") of an element

  • Every node in the tree has a label String

that is either the tag name (e.g., "author")

  • r the text content itself (e.g., "Cay

Horstman")

  • Only tag nodes can have zero or more

attribute name-value pairs, each of which is a String (e.g., "pubDate" → "Dec 20 2011")

5 May 2016 OSU CSE 22

slide-23
SLIDE 23

<book> printISBN → 978-1-118-06331-6 webISBN → 1-118063-31-7 pubDate → Dec 20 2011 <author> <title> <contents> Cay Horstmann Java for Everyone: Late Objects <preface> <chapter> number → 1 title → Introduction <chapter> number → 2 title → Fundamental Data Types <section> title → Chapter Goals <section> title → Chapter Contents <section> number → 1.1 title → Computer Programs <section> number → 1.2 title → The Anatomy of a Computer

. . . . . .

<book> <author> <title> <contents> <preface> <chapter> <chapter> <section> <section> <section> <section>

Tag Nodes and Text Nodes

5 May 2016 OSU CSE 23

Tag node

label = “book” attributes = “printISBN” → “978-1-118-06331-7” “webISBN” → “1-118063-31-7” “pubDate” → “Dec 20 2011”

Text node

label = “Cay Horstmann”

Tag node

label = “preface” No attributes

slide-24
SLIDE 24

Reality Check

  • Carefully examine the example XML file

and the example XMLTree diagram shown earlier to check your understanding of how the file content is modeled by the tree

5 May 2016 OSU CSE 24

slide-25
SLIDE 25

Can You Draw The Tree?

<?xml version="1.0"?> <buckeyes> <location stadium="home" /> Go Bucks! <game opp="UAB" date="22 Sep 2012"> <forecast>Sunny</forecast> </game> </buckeyes>

5 May 2016 OSU CSE 25

slide-26
SLIDE 26

Resources

  • OSU CSE Components API: XMLTree

– http://cse.osu.edu/software/common/doc/

5 May 2016 OSU CSE 26