$30 off During Our Annual Pro Sale. View Details »

XML is Dead. Long Live XML! (IPC2013SE 2013-06-04)

XML is Dead. Long Live XML! (IPC2013SE 2013-06-04)

Presentation given at International PHP Conference 2013 Spring Edition in Berlin, Germany.

David Zuelke

June 04, 2013
Tweet

More Decks by David Zuelke

Other Decks in Programming

Transcript

  1. XML IS DEAD.
    LONG LIVE XML!

    View Slide

  2. David Zülke

    View Slide

  3. David Zuelke

    View Slide

  4. View Slide

  5. http://en.wikipedia.org/wiki/File:München_Panorama.JPG

    View Slide

  6. Lead Architect

    View Slide

  7. View Slide

  8. @dzuelke

    View Slide

  9. TODAY'S MENU
    • XML (and where it took a wrong turn)
    • HTML 5 (and why it makes me a little bit sad)
    • JSON (and why it's not as universally useful as you may think)
    • YAML (and why it makes my eyes bleed)

    View Slide

  10. but first

    View Slide

  11. I'd like to hear from you, dear audience

    View Slide

  12. what do you love, hate, adore or loathe with a passion?

    View Slide

  13. XML
    eXtensible Markup Language

    View Slide

  14. "extensible" mostly refers to the Namespaces concept
    and the document model

    View Slide

  15. READING AND WRITING
    • Push Parsing, uses events to notify app during parsing
    • Example: SAX
    • Pull Parsing, allows app to retrieve or skip elements
    • Example: PHP's ext/xmlreader
    • DOM, constructs an object representation of the tree
    • Example: DOM (duh)
    Use XMLReader::expand()

    View Slide

  16. VALIDATION
    • XML Schema (validates the grammar of a document)
    • RELAX NG (like XML Schema, just full of win)
    • Except it's so awesome it sucks at reporting errors :(
    • Schematron (validates the semantics of a document)
    • DTD (RRRRRRRAAAAAAAAAAAAAAAAAGGGGEEEE)

    View Slide

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

    View Slide

  18. but most importantly

    View Slide

  19. XML’s document model is built for extensibility

    View Slide



  20.    
           Bacon
           5.99
       

    View Slide

  21. //p:product[1]/p:price[1]  =>  “5.99”
    “p” bound to “http:/
    /acme.com/shop/products”

    View Slide



  22.    
           Bacon
           5.99
           OMNOMNOM  Bacon
       

    View Slide



  23.    
           Bacon
           5.99
       

    View Slide



  24.    
           Bacon
           5.99
       

    View Slide

  25. //p:product[1]/p:price[1]  =>  “5.99”

    View Slide



  26.    
           Bacon
           5.99
           4.49
       

    View Slide

  27. //p:product[1]/p:price[1]  =>  “5.99”

    View Slide



  28.    
           Bacon
           Speck
           5.99
           4.49
       

    View Slide



  29.    
           Bacon
           Speck
           5.99
           
       

    View Slide

  30. XML: doing it right

    View Slide



  31.    6
       2
       1
                       rel="self"  title="self"/>
                       rel="next"  title="next"/>
                       rel="last"  title="last"/>
       
           true
           2003-­‐09-­‐12
           
           http://openapi.lovefilm.com/catalog/title/59643
           false
           574
           4
           
           
           
           
           
                               rel="http://schemas.lovefilm.com/synopsis"  title="synopsis"/>
                               rel="http://schemas.lovefilm.com/reviews"  title="reviews"/>
                               rel="alternate"  title="web  page"/>
       

    View Slide

  32. which brings me to...

    View Slide

  33. HATEOAS AND HYPERMEDIA
    The Main Ingredient For Your REST API

    View Slide

  34. XML: doing it wrong

    View Slide


  35.    "http://www.apple.com/DTDs/PropertyList-­‐1.0.dtd">


           DefaultProfileChoices
           
                   AC  Power
                   2
                   Battery  Power
                   1
                   UPS  Power
                   1
           
           SystemProfileDefaults
           

                   

                           AC  Power
                           
                               
                           
                   
           


    View Slide

  36. but please
    do not serialize objects to XML
    (I'm looking at you, SOAP)

    View Slide

  37. HTML 5
    Such a mess :(

    View Slide

  38. 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 it's not SGML...
    • Completely idiotic stuff like data-* attributes
    • And they're even proud of it...

    View Slide

  39.          data-­‐name="John  Resig"  data-­‐city="Boston"
             data-­‐lang="js"  data-­‐food="Bacon">
       John  says:  Hello,  how  are  you?

    View Slide

  40. but that's already possible in XML!

    View Slide

  41.          xmlns:myapp="http://myapp.com/v1"
             myapp:name="John  Resig"  myapp:city="Boston"
             myapp:lang="js"  myapp:food="Bacon">
       John  says:  Hello,  how  are  you?

    View Slide

  42. JSON
    JavaScript Object Notation

    View Slide

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

    View Slide

  44. win: store arbitrary keys and values

    View Slide

  45. {
           "_id"  :  "bc2a41170621c326ec68382f846d5764",
           "_rev"  :  "2612672603",
           "item"  :  "orange",
           "prices"  :  {
                   "Fresh  Mart"  :  1.99,
                   "Price  Max"  :  3.19,
                   "Citrus  Circus"  :  1.09
           }
    }

    View Slide

  46. fail: use it as query language for your “web scale” database

    View Slide

  47. {  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"  }

    View Slide

  48. EVOLVABILITY
    Because Things Change Over Time!

    View Slide



  49.    1234
       Red  Stapler
                                 href="http://acme.com/products/1234/payment"/>
       3.14

    {
       id:  1234,
       name:  "Red  Stapler",
       links:  [
           {
               rel:  "payment",
               type:  "application/vnd.com.acme.shop+json",
               href:  "http://acme.com/products/1234/payment"
           }
       ],
       price:  3.14
    }
    XML VERSUS JSON

    View Slide



  50.    1234
       Red  Stapler
                                 href="http://acme.com/products/1234/payment"/>
       3.14

    {
       id:  1234,
       name:  "Red  Stapler",
       links:  [
           {
               rel:  "payment",
               type:  "application/vnd.com.acme.shop+json",
               href:  "http://acme.com/products/1234/payment"
           }
       ],
       price:  {
           amount:  3.14,
           currency:  "EUR"
       }
    }
    XML VERSUS JSON
    Content (“node value”) still the same
    Float becomes object, stuff breaks

    View Slide

  51. YAML
    Yet Another Markup Language

    View Slide

  52. YAML
    Yet Another Markup Language
    YAML Ain't Markup Language

    View Slide

  53. recursive acronyms are cool

    View Slide

  54. YAML also was cool at some point

    View Slide

  55. a simple markup language, perfect for configuration files

    View Slide

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

    View Slide

  57. but then...

    View Slide

  58. foo:  |  
           -­‐-­‐-­‐
           foo:  bar
           -­‐-­‐-­‐
           yo:  baz
    bar:  |  
           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.\n\n\n\n"
    -­‐  &showell  Steve
    -­‐  Clark  
    -­‐  Brian  
    -­‐  Oren  
    -­‐  *showell

    View Slide

  59. YAML DRAWBACKS
    • Makes your eyes bleed
    • No schemas or other forms of validation
    • Forget a newline somewhere and the parser might look at
    you, helpless, like a deer in headlights
    • No mixed content

    View Slide

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

    View Slide

  61. !e End

    View Slide

  62. Questions?

    View Slide

  63. THANK YOU!
    This was http://joind.in/8809
    by @dzuelke
    Questions? E-Mail:
    [email protected]

    View Slide