Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Data Interchange Formats

Kalan MacRow
January 25, 2013

Data Interchange Formats

A brief introduction to XML and JSON.

Kalan MacRow

January 25, 2013
Tweet

More Decks by Kalan MacRow

Other Decks in Programming

Transcript

  1. Data interchange formats An introduction to XML and JSON Kalan

    MacRow CPSC 317, Winter 2012 Department of Computer Science The University of British Columbia 1 Sunday, 27 January, 13
  2. Outline XML is new to a lot of us A

    bit of history Why you should care Extensible Markup Language JavaScript Object Notation Connect all the things Data interchange formats: an introduction to XML and JSON. Kalan MacRow, Jan. 2013. 2 Sunday, 27 January, 13
  3. XML what? Quite a few questions about XML... What is

    it? Where does it come from? Why are we using it? What is this stream:stream, xmlns, /> stuff anyway? Data interchange formats: an introduction to XML and JSON. Kalan MacRow, Jan. 2013. 3 Sunday, 27 January, 13
  4. XML Origins Developed by the W3C in the late 1990s

    Descendent of the much older (S)GML (1960s) Influenced XHTML, RSS, Atom, ODF, others Designed for simplicity, interoperability Kind of a sibling of HTML (mid 1990s) Data interchange formats: an introduction to XML and JSON. Kalan MacRow, Jan. 2013. 4 Sunday, 27 January, 13
  5. Why you should care... You need it for Assignment 1!

    Web services, RESTful APIs, RPCs speak XML It is one of two data interchange formats on the web* Tons of stable, open source code for processing it *The other is JSON Data interchange formats: an introduction to XML and JSON. Kalan MacRow, Jan. 2013. 5 Sunday, 27 January, 13
  6. Extensible Markup Language <?xml  version="1.0"?> <note>        <to>David</to>

           <from>Victoria</from>        <heading>Reminder</heading>        <body>Don't  forget  me  this  weekend!</body> </note> Reminder David, don’t forget me this weekend! -Victoria Data interchange formats: an introduction to XML and JSON. Kalan MacRow, Jan. 2013. http://www.w3schools.com/xml/ 6 Sunday, 27 January, 13
  7. Extensible Markup Language var  parser,  note; parser  =  new  window.DOMParser();

    note      =  parser.parseFromString(xmlStr,  “text/xml”); console.log(note.getElementsByTagName(“to”)[0].childNodes[0]); Outputs “David” Data interchange formats: an introduction to XML and JSON. Kalan MacRow, Jan. 2013. 7 Sunday, 27 January, 13
  8. Extensible Markup Language <?xml  version="1.0"  encoding="UTF-­‐8"  standalone="yes"?>   <cp:coreProperties  xmlns:cp=

         "http://schemas.openxmlformats.org/package/2006/metadata/core-­‐properties"        xmlns:dc="http://purl.org/dc/elements/1.1/"  xmlns:dcterms="http://purl.org/dc/terms/"        xmlns:dcmitype="http://purl.org/dc/dcmitype/"  xmlns:xsi=      "http://www.w3.org/2001/XMLSchema-­‐instance">        <dc:title></dc:title>        <dc:subject></dc:subject>        <dc:creator>Your  name</dc:creator>        <cp:keywords></cp:keywords>        <dc:description></dc:description>        <cp:lastModifiedBy>Your  name</cp:lastModifiedBy>        <cp:revision>2</cp:revision>        <dcterms:created  xsi:type="dcterms:W3CDTF">2006-­‐05-­‐03T01:13:00Z</dcterms:created>        <dcterms:modified  xsi:type="dcterms:W3CDTF">2006-­‐05-­‐03T01:14:00Z</dcterms:modified>   </cp:coreProperties>   core.xml (Word Document) Data interchange formats: an introduction to XML and JSON. Kalan MacRow, Jan. 2013. http://msdn.microsoft.com/en-us/library/office/bb264572(v=office.12).aspx 8 Sunday, 27 January, 13
  9. Extensible Markup Language <dcterms:created  xsi:type="dcterms:W3CDTF">2006-­‐05-­‐03T01:13:00Z</dcterms:created> Tag name Namespace Attribute name

    Attribute value Content Anatomy of a tag Data interchange formats: an introduction to XML and JSON. Kalan MacRow, Jan. 2013. 9 Sunday, 27 January, 13
  10. Extensible Markup Language <dcterms:created  xsi:type="dcterms:W3CDTF"></dcterms:created> <dcterms:created  xsi:type="dcterms:W3CDTF"  /> Self-closing tags

    Data interchange formats: an introduction to XML and JSON. Kalan MacRow, Jan. 2013. 10 Sunday, 27 January, 13
  11. JavaScript Object Notation A terse alternative to XML Based on

    JavaScript syntax, but language agnostic Web services, RESTful APIs, RPCs speak JSON! Tons of stable, open source code for processing it Data interchange formats: an introduction to XML and JSON. Kalan MacRow, Jan. 2013. 11 Sunday, 27 January, 13
  12. JavaScript Object Notation {“note”:{          “to”:  “David”,

           “from”:  “Victoria”,   “heading”:  “Reminder”,        “body”:  “Don’t  forget  me  this  weekend!” }}   Reminder David, don’t forget me this weekend! -Victoria Data interchange formats: an introduction to XML and JSON. Kalan MacRow, Jan. 2013. 12 Sunday, 27 January, 13
  13. JavaScript Object Notation var  note; note  =  JSON.parse(jsonStr); console.log(note[“to”]); Outputs

    “David” Data interchange formats: an introduction to XML and JSON. Kalan MacRow, Jan. 2013. 13 Sunday, 27 January, 13
  14. Apps and services communicate over the Internet Often over HTTP(S)

    with XML or JSON Other protocols (XMPP) based on XML or JSON Documents, Graphics, Spreadsheets, Databases based on XML and JSON Data interchange formats: an introduction to XML and JSON. Kalan MacRow, Jan. 2013. 14 Sunday, 27 January, 13