XML - The Versatile Data Format

consuming n.w
1 / 16
Embed
Share

XML, or Extensible Markup Language, is a powerful tool for structuring, storing, and transporting data in a software and hardware-independent manner. Unlike HTML, which focuses on data presentation, XML emphasizes what the data is rather than how it looks. Through separating data from HTML and enabling dynamic data display, XML simplifies data sharing and transport through plain text format. This versatile data format forms tree-like structures, making it easy to represent and manipulate information efficiently across different applications.

  • XML
  • Data format
  • Information sharing
  • Markup language

Uploaded on | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. Consuming eXtensible Markup Language (XML) feeds

  2. What is XML? XML Stands for eXtensible Markup Language Is designed to transport and store data with focus on what data is As opposed to HTML that was designed to display data with focus on how data looks Tags are not predefined The tags used in HTML are predefined <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</h eading> <body>Don't forget me this weekend!</body> </note> HTML docs use tags defined in HTML standard Does not do anything Created to structure, store, and transport information is a Software and hardware-independent tool For carrying information

  3. How can XML be used? Separate data from HTML Displaying dynamic data in your HTML document Simplify data sharing/transport XML is stored in plain text format => Software and hardware-independent data sharing Greatly reducing complexity of data transport Between incompatible applications

  4. XML tree XML documents Form a tree structure Starting at root and branching to leaves Example XML document: <?xml version="1.0" encoding="ISO-8859-1"?> <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note>

  5. Tree representation of an XML doc: Example <bookstore> <book category="COOKING"> <title lang="en">Everyday Italian</title> <author>Giada De Laurentiis</author> <year>2005</year> <price>30.00</price> </book> <book category="CHILDREN"> <title lang="en">Harry Potter</title> <author>J K. Rowling</author> <year>2005</year> <price>29.99</price> </book> <book category="WEB"> <title lang="en">Learning XML</title> <author>Erik T. Ray</author> <year>2003</year> <price>39.95</price> </book> </bookstore>

  6. XML elements An element can contain Other elements <bookstore> <book category="CHILDREN"> <title>Harry Potter</title> <author>J K. Rowling</author> <year>2005</year> <price>29.99</price> </book> <book category="WEB"> <title>Learning XML</title> <author>Erik T. Ray</author> <year>2003</year> <price>39.95</price> </book> </bookstore> Text Attributes Or a mix of the above

  7. Well-formed XML docs The syntax rules XML docs must have a root element XML elements must have a closing tag XML tags are case sensitive <Message>This is incorrect</message> XML elements must be properly nested <b><i>This text is bold and italic</i></b> XML attributes must be quoted <note date="12/11/2007"> <to>Tove</to> <from>Jani</from> </note>

  8. Document Object Model (DOM) DOM Is a tree structure where each node Contains one of the components of an XML structure The two most common nodes are Element nodes and text nodes Provides an API for processing XML files Instantiate the Factory Create a document builder Get a parser and parse the file

  9. DOM Nodes Node nodeName nodeValue Attributes Attr Name of attribute Value of attribute null CDATASection #cdata-section Content of the CDATA section Content of the comment null null Comment #comment null Document #document null DocumentFragment #documentFragment null null DocumentType Document Type name null null Element Tag name null null Entity Entity name null null EntityReference Name of entity referenced Notation name null null Notation null null ProcessingInstruction Target Entire content excluding the target Content of the text node null Text #text null

  10. Classes for Processing XML files Document Represents the entire XML document Providing primary access to the document s data Methods getElementsByTagName(String tagname) Returns a NodeList of all Nodes with a given tag name Node Represents a single node in the document tree getNodeName()/getNodeValue() return The name/value as a string of the node depending on its type getFirstChild()/getLastChild()/getChildNodes()

  11. Classes for Processing XML files (continued) NodeList Ordered collection of nodes, where Items accessible via an integral index Methods item(int index) Returns the Node at index. NamedNodeMap Collection of nodes that can be accessed by name Methods Node item(int index) Node getNamedItem(String name)

  12. Classes for Processing XML files (cont d) Element Represents an element in XML that May have attributes associated with them Has methods to retrieve attributes by name or by value String getAttribute(String name) Retrieves an attribute name by name Attr getAttributeNode(String name) Retrieves an attribute node by name Attr Represents an attribute in an Element object String getName() String getValue()

  13. Consuming Java Script Object Notation (JSON) feeds

  14. What is JSON? JSON stands for JavaScript Object Notation is syntax for storing and exchanging text information Much like XML is smaller than XML, and faster and easier to parse { "employees": [ { "firstName":"John" , "lastName":"Doe" }, { "firstName":"Anna" , "lastName":"Smith" }, { "firstName":"Peter" , "lastName":"Jones" } ] }

  15. Contrasting XML to JSON Similarities: both are Plain-text Self-describing (human readable) Hierarchical (values nested within values) Differences: JSON Uses no end tags Is shorter Quicker to read and write Uses arrays

  16. JSON syntax JSON data written as name/value pairs "firstName" : "John" Separated by commas (,) JSON objects Enclosed in curly brackets ({}) { "firstName":"John" , "lastName":"Doe" } JSON arrays Delineated by square brackets ([]) { "employees": [ { "firstName":"John" , "lastName":"Doe" }, { "firstName":"Anna" , "lastName":"Smith" }, { "firstName":"Peter" , "lastName":"Jones" } ] }

Related


More Related Content