xmltree model
play

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


  1. XMLTree Model 5 May 2016 OSU CSE 1

  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

  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

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

  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

  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

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

  8. Top-Level Element = Root of Tree The attribute name-value <book printISBN="978-1-118-06331-6" pairs of an element/tag are webISBN="1-118063-31-7" in the tree node of that pubDate="Dec 20 2011"> element/tag. ... </book> 5 May 2016 OSU CSE 8

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

  10. Top-Level Element = Root of Tree The children of the <book printISBN="978-1-118-06331-6" top-level element/tag webISBN="1-118063-31-7" are the children of pubDate="Dec 20 2011"> the root of the tree. ... </book> 5 May 2016 OSU CSE 10

  11. Top-Level Element = Root of Tree The first child node of <book printISBN="978-1-118-06331-6" the root is known as webISBN="1-118063-31-7" “child 0” because pubDate="Dec 20 2011"> children are ... numbered from 0. </book> 5 May 2016 OSU CSE 11

  12. Top-Level Element = Root of Tree The second child node <book printISBN="978-1-118-06331-6" of the root is known as webISBN="1-118063-31-7" “child 1”. pubDate="Dec 20 2011"> ... </book> 5 May 2016 OSU CSE 12

  13. Top-Level Element = Root of Tree The third child node of <book printISBN="978-1-118-06331-6" the root is known as webISBN="1-118063-31-7" “child 2”. pubDate="Dec 20 2011"> ... </book> 5 May 2016 OSU CSE 13

  14. First Child Element = First Child Node <book ...> <author>Cay Horstmann</author> ... </book> 7 January 2019 OSU CSE 14

  15. First Child Element = First Child Node <book ...> <author> Cay Horstmann </author> ... </book> 5 May 2016 OSU CSE 15

  16. First Child Element = First Child Node <book ...> <author> Cay Horstmann </author> ... </book> 5 May 2016 OSU CSE 16

  17. First Child Element = First Child Node <book ...> <author> Cay Horstmann </author> ... </book> 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 . 5 May 2016 OSU CSE 17

  18. Second Child Element = Second Child Node <book ...> ... <title>Java for Everyone: Late Objects</title> ... </book> 5 May 2016 OSU CSE 18

  19. Second Child Element = Second Child Node <book ...> ... <title> Java for Everyone: Late Objects </title> ... </book> 5 May 2016 OSU CSE 19

  20. Second Child Element = Second Child Node <book ...> ... <title> Java for Everyone: Late Objects </title> ... </book> 5 May 2016 OSU CSE 20

  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

  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" ) or 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

  23. Tag Nodes and Text Nodes Tag node <book> <book> label = “book” attributes = printISBN → 978-1-118-06331-6 webISBN → 1-118063-31-7 “printISBN” → “978-1-118-06331-7” pubDate → Dec 20 2011 “webISBN” → “1-118063-31-7” “pubDate” → “Dec 20 2011” <author> <author> <title> <contents> <title> <contents> Java for Everyone: Cay Horstmann <chapter> <chapter> <chapter> <chapter> Late Objects . . . Tag node <preface> <preface> number → 1 number → 2 title → Introduction title → Fundamental Data Types label = “preface” No attributes Text node <section> <section> <section> <section> <section> <section> <section> <section> . . . label = “Cay Horstmann” number → 1.1 number → 1.2 title → Chapter Goals title → Chapter Contents title → Computer Programs title → The Anatomy of a Computer 5 May 2016 OSU CSE 23

  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

  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

  26. Resources • OSU CSE Components API: XMLTree – http://cse.osu.edu/software/common/doc/ 5 May 2016 OSU CSE 26

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend