XML versus the New Kids on the Block (PHPBNL11 2011-01-29)
Upcoming SlideShare
Loading in...5

XML versus the New Kids on the Block (PHPBNL11 2011-01-29)



Presentation given at PHP Benelux Conference 2011

Presentation given at PHP Benelux Conference 2011



Total Views
Views on SlideShare
Embed Views



3 Embeds 4

http://ben.local 2
http://potherca.local 1
http://paper.li 1



Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
Post Comment
Edit your comment

XML versus the New Kids on the Block (PHPBNL11 2011-01-29) XML versus the New Kids on the Block (PHPBNL11 2011-01-29) Presentation Transcript

  • David Zülke
  • David Zuelke
  • http://en.wikipedia.org/wiki/File:München_Panorama.JPG
  • Founder
  • Lead Developer
  • @dzuelke
  • TODAYS MENU• XML (and where it took a wrong turn)• HTML 5 (and why it makes me very, very angry)• JSON (and why its not always as useful as you may think)• YAML (and why it makes my eyes bleed)
  • but first
  • Id like to hear from you, dear audience
  • what do you love, hate, adore or loathe with a passion?
  • XMLeXtensible Markup Language
  • "extensible" mostly refers to the Namespaces concept
  • VALIDATION• XML Schema (validates the grammar of a document)• RELAX NG (like XML Schema, just full of win) • Except its so awesome it sucks at reporting errors :(• Schematron (validates the semantics of a document)• DTD (RRRRRRRAAAAAAAAAAAAAAAAAGGGGEEEE)
  • OTHER GOODIES• XPath and XQuery for querying documents • XPath is an expression syntax, XQuery a full query language• XSLT to transform documents to XML, HTML, text, ... • Makes heavy use of XPath• XIncludes • Allow re-use of content within and across documents
  • READING AND WRITING• Push Parsing, uses events to notify app during parsing • Example: SAX• Pull Parsing, allows app to retrieve or skip elements • Example: PHPs ext/xmlreader• DOM, constructs an object representation of the tree • Example: DOM (duh)
  • but most importantly
  • Mixed Content!
  • <?xml  version="1.0"  encoding="utf-­‐8"?><products  xmlns="http://acme.com/shop/products">    <product  id="123">        <name>Bacon</name>        <price>5.99</price>    </product></products>
  • <?xml  version="1.0"  encoding="utf-­‐8"?><products  xmlns="http://acme.com/shop/products">    <product  id="123">        <name>Bacon</name>        <price>5.99</price>        OMNOMNOM  Bacon    </product></products>
  • and you can add elements without changing the structure
  • <?xml  version="1.0"  encoding="utf-­‐8"?><products  xmlns="http://acme.com/shop/products">    <product  id="123">        <name>Bacon</name>        <price>5.99</price>    </product></products>
  • <?xml  version="1.0"  encoding="utf-­‐8"?><products  xmlns="http://acme.com/shop/products">    <product  id="123">        <name  xml:lang="en">Bacon</name>        <name  xml:lang="de">Speck</name>        <price>5.99</price>    </product></products>
  • <?xml  version="1.0"  encoding="utf-­‐8"?><products  xmlns="http://acme.com/shop/products">    <product  id="123">        <name  xml:lang="en">Bacon</name>        <name  xml:lang="de">Speck</name>        <price>5.99</price>        <link  rel="category"  href="..."  />    </product></products>
  • XML: doing it right
  • <?xml  version="1.0"  encoding="utf-­‐8"  standalone="yes"?><search>    <total_results>6</total_results>    <items_per_page>2</items_per_page>    <start_index>1</start_index>    <link  href="http://openapi.lovefilm.com/catalog/games?start_index=1&amp;items_per_page=2&amp;term=old"                rel="self"  title="self"/>    <link  href="http://openapi.lovefilm.com/catalog/games?start_index=3&amp;items_per_page=2&amp;term=old"                rel="next"  title="next"/>    <link  href="http://openapi.lovefilm.com/catalog/games?start_index=5&amp;items_per_page=2&amp;term=old"                rel="last"  title="last"/>    <catalog_title>        <can_rent>true</can_rent>        <release_date>2003-­‐09-­‐12</release_date>        <title  full="Star  Wars:  Knights  of  the  Old  Republic"  clean="Star  Wars:  Knights  of  the  Old  Republic"/>        <id>http://openapi.lovefilm.com/catalog/title/59643</id>        <adult>false</adult>        <number_of_ratings>574</number_of_ratings>        <rating>4</rating>        <category  scheme="http://openapi.lovefilm.com/categories/catalog"  term="games"/>        <category  scheme="http://openapi.lovefilm.com/categories/format"  term="Xbox"/>        <category  scheme="http://openapi.lovefilm.com/categories/genres"  term="Adventure"/>        <category  scheme="http://openapi.lovefilm.com/categories/genres"  term="Role-­‐playing"/>        <category  scheme="http://openapi.lovefilm.com/categories/certificates/bbfc"  term="TBC"/>        <link  href="http://openapi.lovefilm.com/catalog/title/59643/synopsis"                    rel="http://schemas.lovefilm.com/synopsis"  title="synopsis"/>        <link  href="http://openapi.lovefilm.com/catalog/title/59643/reviews"                    rel="http://schemas.lovefilm.com/reviews"  title="reviews"/>        <link  href="http://www.lovefilm.com/product/59643-­‐Star-­‐Wars-­‐Knights-­‐of-­‐the-­‐Old-­‐Republic.html?cid=LFAPI"                    rel="alternate"  title="web  page"/>    </catalog_title></search>
  • which brings me to...
  • HATEOAS AND HYPERMEDIA The Main Ingredient For Your REST API
  • XML: doing it wrong
  • <?xml  version="1.0"  encoding="UTF-­‐8"?><!DOCTYPE  plist  PUBLIC  "-­‐//Apple  Computer//DTD  PLIST  1.0//EN"    "http://www.apple.com/DTDs/PropertyList-­‐1.0.dtd"><plist  version="1.0"><dict>        <key>DefaultProfileChoices</key>        <dict>                <key>AC  Power</key>                <integer>2</integer>                <key>Battery  Power</key>                <integer>1</integer>                <key>UPS  Power</key>                <integer>1</integer>        </dict>        <key>SystemProfileDefaults</key>        <array><!-­‐-­‐  Profile  0  -­‐-­‐>                <dict><!-­‐-­‐  AC  Power  -­‐  unused  -­‐-­‐>                        <key>AC  Power</key>                        <dict>                            <!-­‐-­‐  ...  -­‐-­‐>                        </dict>                </dict>        </array></dict></plist>
  • but pleasedo not serialize objects to XML (Im looking at you, SOAP)
  • HTML 5Such a mess :(
  • HTML 5• Neither SGML nor XML • so browser vendors need to write new (inefficient) parsers• Does not have a DTD anymore • how could it, given how its not SGML...• Completely idiotic stuff like data-* attributes • And theyre even proud of it...
  • <li  class="user"          data-­‐name="John  Resig"  data-­‐city="Boston"          data-­‐lang="js"  data-­‐food="Bacon">    <b>John  says:</b>  <span>Hello,  how  are  you?</span></li>
  • but thats already possible in XML!
  • <li  class="user"          xmlns:myapp="http://myapp.com/v1"          myapp:name="John  Resig"  myapp:city="Boston"          myapp:lang="js"  myapp:food="Bacon">    <b>John  says:</b>  <span>Hello,  how  are  you?</span></li>
  • also
  • they dropped support for PUT & DELETE in forms
  • JSONJavaScript Object Notation
  • JSON KEY FEATURES• Quite efficient, simple, universally supported in many languages• Very good for serializing objects• Built-in types, do not need explicit declaration• No schemas• No mixed content
  • win: store arbitrary keys and values
  • {        "_id"  :  "bc2a41170621c326ec68382f846d5764",        "_rev"  :  "2612672603",        "item"  :  "orange",        "prices"  :  {                "Fresh  Mart"  :  1.99,                "Price  Max"  :  3.19,                "Citrus  Circus"  :  1.09        }}
  • fail: use it as query language for your pile of crap database
  • {  foo:  "bar"  }{  x  :  3,  y  :  "foo"  }{  $or  :  [  {  a  :  1  }  ,  {  b  :  2  }  ]  }{  j  :  {  $ne:  3  },  k  :  {  $gt:  10  }  }{  x  :  3  },  {  z  :  1  }{  j  :  {  $in  :  [2,4,6]  }  }{  "author.name"  :  "joe"  }{  "addresses.city"  :  "London"  }
  • YAMLYet Another Markup Language
  • YAMLYet Another Markup LanguageYAML Aint Markup Language
  • recursive acronyms are cool
  • YAML also was cool at some point
  • a simple markup language, perfect for configuration files
  • autoload:    #  plugins    plugins_lib:        name:                      plugins  lib        path:                      %SF_PLUGINS_DIR%/*/lib        recursive:            true        exclude:                []            plugins_module_lib:        name:                      plugins  module  lib        path:                      %SF_PLUGINS_DIR%/*/modules/*/lib        prefix:                  2        recursive:            true        exclude:                []    #  project    project:        name:                      project        path:                      %SF_LIB_DIR%        recursive:            true        exclude:                [model,  symfony,  deprecated]
  • but then...
  • foo:  |          -­‐-­‐-­‐        foo:  bar        -­‐-­‐-­‐        yo:  bazbar:  |          fooness        clipped:  |        This  has  one  newline.same  as  "clipped"  above:  "This  has  one  newline.n"stripped:  |-­‐        This  has  no  newline.same  as  "stripped"  above:  "This  has  no  newline."kept:  |+        This  has  four  newlines.same  as  "kept"  above:  "This  has  four  newlines.nnnn"-­‐  &showell  Steve-­‐  Clark  -­‐  Brian  -­‐  Oren  -­‐  *showell
  • YAML DRAWBACKS• Makes your eyes bleed• No schemas or other forms of validation• Forgeta newline somewhere and the parser might look at you, helpless, like a deer in headlights• No mixed content
  • CONCLUSION• XML for hypermedia, documents, your new REST API• JSON for serializing objects and storing them in e.g. CouchDB• YAML for your configuration files
  • !e End
  • Questions?
  • THANK YOU! This was http://joind.in/2414 by @dzuelkeSend me questions or hire us:david.zuelke@bitextender.com