/
Consuming  eXtensible Markup Language (XML) feeds Consuming  eXtensible Markup Language (XML) feeds

Consuming eXtensible Markup Language (XML) feeds - PowerPoint Presentation

taylor
taylor . @taylor
Follow
1 views
Uploaded On 2024-03-15

Consuming eXtensible Markup Language (XML) feeds - PPT Presentation

What is XML XML Stands for e X tensible  M arkup  L anguage 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 ID: 1048446

year xml price book xml year book price author title data firstname lastname node json note string text nodes

Share:

Link:

Embed:

Download Presentation from below link

Download Presentation The PPT/PDF document "Consuming eXtensible Markup Language (X..." is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

1. Consuming eXtensible Markup Language (XML) feeds

2. What is XML?XMLStands for eXtensible Markup LanguageIs designed to transport and store data with focus on what data isAs opposed to HTML that was designed to display data with focus on how data looksTags are not predefinedThe tags used in HTML are predefined HTML docs use tags defined in HTML standardDoes not do anythingCreated to structure, store, and transport informationis a Software and hardware-independent tool For carrying information<note><to>Tove</to><from>Jani</from><heading>Reminder</heading><body>Don't forget me this weekend!</body></note>

3. How can XML be used? Separate data from HTMLDisplaying dynamic data in your HTML documentSimplify data sharing/transportXML is stored in plain text format =>Software and hardware-independent data sharingGreatly reducing complexity of data transportBetween incompatible applications

4. XML treeXML documentsForm a tree structure Starting at root and branching to leavesExample 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 elementsAn element can containOther elementsTextAttributesOr a mix of the above<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>

7. Well-formed XML docsThe syntax rulesXML docs must have a root elementXML elements must have a closing tagXML tags are case sensitiveXML elements must be properly nestedXML attributes must be quoted<b><i>This text is bold and italic</i></b><Message>This is incorrect</message><note date="12/11/2007">  <to>Tove</to>  <from>Jani</from></note>

8. Document Object Model (DOM)DOMIs a tree structure where each node Contains one of the components of an XML structureThe two most common nodes areElement nodes and text nodesProvides an API for processing XML filesInstantiate the Factory Create a document builderGet a parser and parse the file

9. DOM NodesNodenodeNamenodeValueAttributesAttrName of attributeValue of attributenullCDATASection#cdata-sectionContent of the CDATA sectionnullComment#commentContent of the commentnullDocument#documentnullnullDocumentFragment#documentFragmentnullnullDocumentTypeDocument Type namenullnullElementTag namenullnullEntityEntity namenullnullEntityReferenceName of entity referencednullnullNotationNotation namenullnullProcessingInstructionTargetEntire content excluding the targetnullText#textContent of the text nodenull

10. Classes for Processing XML filesDocumentRepresents the entire XML documentProviding primary access to the document’s dataMethodsgetElementsByTagName(String tagname)Returns a NodeList of all Nodes with a given tag nameNodeRepresents a single node in the document treegetNodeName()/getNodeValue() returnThe name/value as a string of the node depending on its typegetFirstChild()/getLastChild()/getChildNodes()

11. Classes for Processing XML files (continued)NodeListOrdered collection of nodes, whereItems accessible via an integral indexMethodsitem(int index)Returns the Node at index. NamedNodeMapCollection of nodes that can be accessed by nameMethodsNode item(int index) Node getNamedItem(String name)

12. Classes for Processing XML files (cont’d) ElementRepresents an element in XML thatMay have attributes associated with themHas methods to retrieve attributes by name or by valueString getAttribute(String name)Retrieves an attribute name by nameAttr getAttributeNode(String name)Retrieves an attribute node by nameAttrRepresents an attribute in an Element objectString getName()String getValue()

13. Consuming Java Script Object Notation (JSON) feeds

14. What is JSON? JSONstands for JavaScript Object Notationis syntax for storing and exchanging text informationMuch like XMLis 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 JSONSimilarities: both arePlain-textSelf-describing (human readable)Hierarchical (values nested within values)Differences:JSON Uses no end tagsIs shorterQuicker to read and writeUses arrays

16. JSON syntaxJSON datawritten as name/value pairsSeparated by commas (,)JSON objectsEnclosed in curly brackets ({})JSON arraysDelineated by square brackets ([])"firstName" : "John"{ "firstName":"John" , "lastName":"Doe" }{"employees": [{ "firstName":"John" , "lastName":"Doe" }, { "firstName":"Anna" , "lastName":"Smith" }, { "firstName":"Peter" , "lastName":"Jones" }]}