SlideShare a Scribd company logo
1 of 84
Markup Languages und Anwendungen




Marc Seeger (20488)
mail@marc-seeger.de
Computer Science and Media,
HdM Stuttgart, WS 08/09
Ruby

    XML Mapping Libraries

    YAML

A language that doesn't
affect the way you think
about programming, is not
worth knowing
                 Alan Perlis
Origin:

     Yukihiro quot;Matzquot; Matsumoto
     Japan 1993




    1st english book: 2000

    Ruby on Rails: 2004

Variable Declaration:





    Function Declaration:

                            do_something(quot;Marcquot;, 4)
                            
                            MarcMarcMarc
                            12
ClassNames

    method_names and variable_names

    methods_asking_a_question?

    slightly_dangerous_methods!

    @instance_variables

    $global_variables

    SOME_CONSTANTS or OtherConstants

Principle of Least Surprise
?
No Primitives, Integers and floats are objects!

     -1.abs => 1
;
No Semi-colons
nil, not null

    nil is an object!

     nil.nil? => true
     nil.class => NilClass
    nil and false are false

     everything else, including 0, is true
Expression oriented syntax.

     Almost everything returns a value
     Methods automatically return their last
     expression.
Single Inheritance

     But mixins are available (= Interface with implemented methods)
 This module implements the mixin




  A class that doesn‘t do that much




  inheriting
  and mixing!



We inherited that one
And mixed in that one
Classes are always open (even built in classes)
 




Another Example from Rails:
1.hour.from_now
Procedural

    Object Oriented

    Functional

irb(main):001:0> 42.methods
=> [quot;%quot;, quot;odd?quot;, quot;inspectquot;, quot;prec_iquot;, quot;<<quot;, quot;tapquot;, quot;divquot;, quot;&quot;, quot;clonequot;, quot;>>quot;, quot;p
ublic_methodsquot;, quot;__send__quot;, quot;instance_variable_defined?quot;, quot;equal?quot;, quot;freezequot;,
„to_symquot;, quot;*quot;, quot;ordquot;, quot;+quot;, quot;extendquot;, quot;nextquot;, quot;sendquot;, quot;roundquot;, quot;methodsquot;,
quot;prec_f„, quot;-quot;, quot;even?quot;, quot;singleton_method_addedquot;, quot;divmodquot;, quot;hashquot;, quot;/quot;,
quot;integer?quot;, quot;downtoquot;, quot;dupquot;, quot;instance_variablesquot;, quot;|quot;, quot;eql?quot;, quot;sizequot;,
quot;object_idquot;, quot;instance_evalquot;, quot;truncatequot;, quot;~quot;, quot;idquot;, quot;to_iquot;, quot;singleton_methodsquot;,
[…]

irb(main):005:0> nil.class
=> NilClass

irb(main):002:0> nil.hallo_hdm
NoMethodError: undefined method `hallo_hdm' for nil:NilClass
    from (irb):2
Strong typing

     ▪ quot; 5 quot; / 2  „NoMethodError“
    Weak typing

     ▪ quot; 16 quot; / 2  8 (e.g. in Perl)




Ruby is strongly typed! (Java too)
Explicit: int a = 5

    Implicit: a = 5





Ruby is implicitly typed! (Java explicitly)
Static typing

     The compiler checks types during compilation
    Dynamic typing

     The compiler doesn‘t check types during
     compilation




Ruby uses dynamic typing (Java uses static typing)
„Blocks are unnamed functions“
Define:




Call:




Result:
The current piece of
                        What we are going
the collection we are
                        to do with it
working with
A closure object has:
•code to run (the executable)
•state around the code (the scope)

So you capture the environment, namely the local variables, in the
closure. As a result, you can refer to the local variables inside a closure
Idea: Function returning a function




In action:
Ruby VM (Ruby 1.8)

    YARV (aka Ruby 1.9)

    Rubinius

    MacRuby

    Jruby

    IronRuby

    Hotruby

Gem:



     Search:




     Installing:
Gem:


     Usage:
Enough with the
 Jibber-Jabber
XML  Object

     XML-Object
     XmlSimple
    XML  Object

     ROXML
     XML::MAPPING
     HappyMapper
http://xml-object.rubyforge.org/




„Tools like JSON or YAML are a much
better fit for this kind of job, but one
doesn’t always have that luxury.“
… attempts to make the accessing of small,
well-formed XML structures convenient, by
providing a syntax that fits well in most Ruby
programs.
>ruby test.rb
At first, Elements are checked: Bread Recepie
You can get the Attributes though: an awesome recepie for bread
Question notation
                                                                                                              enabled?)
Elements or attributes that look like booleans are “booleanized” if called by their question names (such as
Question notation
                                                                                                              enabled?)
Elements or attributes that look like booleans are “booleanized” if called by their question names (such as
Question notation
                                                                                                              enabled?)
Elements or attributes that look like booleans are “booleanized” if called by their question names (such as
Question notation
                                                                                                              enabled?)
Elements or attributes that look like booleans are “booleanized” if called by their question names (such as
Question notation
                                                                                                              enabled?)
Elements or attributes that look like booleans are “booleanized” if called by their question names (such as
Recursive
The design of the adapters assumes parsing of the objects recursively.
Deep files are bound to throw SystemStackError, but for the kinds of
files I need to read, things are working fine so far. In any case, stream
parsing is on the TODO list.
http://xml-simple.rubyforge.org/




                             a Ruby translation of
                             Grant McLean's Perl
                             module XML::Simple
xml_in()

    xml_out()

The input file
                 A hash containing options
Usage:
http://roxml.rubyforge.org/




                              ROXML
roxml_1.0_beta   roxml-1.0_beta     June 28, 2006


ROXML 1.0         roxml-1.0.zip      July 1, 2006


                                   September 24,
ROXML 1.1 Beta   ROXML 1.1 Beta
                                       2006


ROXML 1.2          ROXML 1.2      November 10, 2007


ROXML                 2.2.0       November 3, 2008
ROXML Features
 Read Ruby objects from XML
 Write Ruby objects to XML
 Annotation-style methods for XML mapping
 One-to-one (composition) Ruby to XML
 One-to-many (aggregation) Ruby with array
  to XML


                            Source: http://roxml.rubyforge.org
http://xml-mapping.rubyforge.org/




≈ROXML
}
XML::Mapping::ArrayNode
XML::Mapping::BooleanNode
XML::Mapping::HashNode
XML::Mapping::NumericNode               single-attribute nodes
XML::Mapping::ObjectNode
XML::Mapping::SingleAttributeNode
XML::Mapping::SubObjectBaseNode
XML::Mapping::TextNode

XML::Mapping::ChoiceNode
http://happymapper.rubyforge.org/



               „Making XML fun again“
typecasts



has many
Camel Case XML Tags to Ruby method names
(rhymes with “camel”)
easily readable by humans.
1.
     matches the native data structures of agile
2.
     languages.
     portable between programming languages.
3.
     consistent model to support generic tools.
4.
     supports one-pass processing.
5.
     expressive and extensible.
6.
     easy to implement and use.
7.
JSON/YAML = human readable data interchange format




    JSON == simplicity + universality

     trivial to generate and parse
     reduced human readability
    YAML == human readability + serializing native data structures

     harder to generate and parse
     easy to read
JSON

   YAML




JSON.valid? YAML.valid!
…is Sequences, Maps, Scalars

     Seq = Array
     Map = Hash
     Scalars = String, Integer, Float, Time, NilClass
Sequence:




Array:
Map:




Hash:
Map of
Scalars:




Hash of
Objects:




 Native typing is implicity determined in plain scalars.
YAML output:





    YAML input:

More than 1 document





    Ruby code





    Output

Won‘t somebody please think of
    the children objects!
Live Demo :D

Problem: The !ruby/object type is only understood by YAML.rb.

Solution:
http://www.kuwata-lab.com/kwalify/




    YAML and JSON are simple and nice format

    for structured data and easier for human to
    read and write than XML. But there have
    been no schema for YAML such as RelaxNG or
    DTD. Kwalify gets over this situation.
Fragen?
Each project‘s website

    Some useful closures in Ruby

    http://www.randomhacks.net/articles/2007/02/01/some-useful-closures-in-ruby
    Kai Jäger: Ajax in der Praxis Grundlagen, Konzepte, Lösungen

    ISBN-10: 3-540-69333-5
    Using Ruby - An Introduction to Ruby for Java Programmers

    http://onestepback.org/articles/usingruby/index.html
    Ruby for Java Programmers

    http://www.softwaresummit.com/2006/speakers/BowlerRubyForJavaProgrammers.pdf
    Happy Mapper: Making XML fun again:

    http://railstips.org/2008/11/17/happymapper-making-xml-fun-again
    YAML Working draft 1.2

    http://yaml.org/spec/1.2/
    YAML Cookbook:

    http://www.nt.ntnu.no/users/haugwarb/Programming/YAML/YAML_for_ruby.html

More Related Content

What's hot

Static or Dynamic Typing? Why not both?
Static or Dynamic Typing? Why not both?Static or Dynamic Typing? Why not both?
Static or Dynamic Typing? Why not both?Mario Camou Riveroll
 
XML Schema Patterns for Databinding
XML Schema Patterns for DatabindingXML Schema Patterns for Databinding
XML Schema Patterns for DatabindingPaul Downey
 
An Introduction to JavaScript
An Introduction to JavaScriptAn Introduction to JavaScript
An Introduction to JavaScripttonyh1
 
Amber and beyond: Java language changes
Amber and beyond: Java language changesAmber and beyond: Java language changes
Amber and beyond: Java language changesStephen Colebourne
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScriptAndres Baravalle
 
10 Things I Hate About Scala
10 Things I Hate About Scala10 Things I Hate About Scala
10 Things I Hate About ScalaMeir Maor
 
Rails 3 Beginner to Builder 2011 Week 2
Rails 3 Beginner to Builder 2011 Week 2Rails 3 Beginner to Builder 2011 Week 2
Rails 3 Beginner to Builder 2011 Week 2Richard Schneeman
 
Pxb For Yapc2008
Pxb For Yapc2008Pxb For Yapc2008
Pxb For Yapc2008maximgrp
 
Scala : language of the future
Scala : language of the futureScala : language of the future
Scala : language of the futureAnsviaLab
 
Functional Java 8 - Introduction
Functional Java 8 - IntroductionFunctional Java 8 - Introduction
Functional Java 8 - IntroductionŁukasz Biały
 
Your First Scala Web Application using Play 2.1
Your First Scala Web Application using Play 2.1Your First Scala Web Application using Play 2.1
Your First Scala Web Application using Play 2.1Matthew Barlocker
 
Clojure in real life 17.10.2014
Clojure in real life 17.10.2014Clojure in real life 17.10.2014
Clojure in real life 17.10.2014Metosin Oy
 

What's hot (20)

Static or Dynamic Typing? Why not both?
Static or Dynamic Typing? Why not both?Static or Dynamic Typing? Why not both?
Static or Dynamic Typing? Why not both?
 
Javascript Best Practices
Javascript Best PracticesJavascript Best Practices
Javascript Best Practices
 
XML Schema Patterns for Databinding
XML Schema Patterns for DatabindingXML Schema Patterns for Databinding
XML Schema Patterns for Databinding
 
Code generating beans in Java
Code generating beans in JavaCode generating beans in Java
Code generating beans in Java
 
An Introduction to JavaScript
An Introduction to JavaScriptAn Introduction to JavaScript
An Introduction to JavaScript
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
Java script
Java scriptJava script
Java script
 
Amber and beyond: Java language changes
Amber and beyond: Java language changesAmber and beyond: Java language changes
Amber and beyond: Java language changes
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
10 Things I Hate About Scala
10 Things I Hate About Scala10 Things I Hate About Scala
10 Things I Hate About Scala
 
Rails 3 Beginner to Builder 2011 Week 2
Rails 3 Beginner to Builder 2011 Week 2Rails 3 Beginner to Builder 2011 Week 2
Rails 3 Beginner to Builder 2011 Week 2
 
Pxb For Yapc2008
Pxb For Yapc2008Pxb For Yapc2008
Pxb For Yapc2008
 
camel-scala.pdf
camel-scala.pdfcamel-scala.pdf
camel-scala.pdf
 
Scala : language of the future
Scala : language of the futureScala : language of the future
Scala : language of the future
 
DSLs in JavaScript
DSLs in JavaScriptDSLs in JavaScript
DSLs in JavaScript
 
Java SE 8 best practices
Java SE 8 best practicesJava SE 8 best practices
Java SE 8 best practices
 
UT on Rails3 2010- Week 2
UT on Rails3 2010- Week 2UT on Rails3 2010- Week 2
UT on Rails3 2010- Week 2
 
Functional Java 8 - Introduction
Functional Java 8 - IntroductionFunctional Java 8 - Introduction
Functional Java 8 - Introduction
 
Your First Scala Web Application using Play 2.1
Your First Scala Web Application using Play 2.1Your First Scala Web Application using Play 2.1
Your First Scala Web Application using Play 2.1
 
Clojure in real life 17.10.2014
Clojure in real life 17.10.2014Clojure in real life 17.10.2014
Clojure in real life 17.10.2014
 

Similar to Ruby Xml Mapping

ABRIDGED VERSION - Joys & frustrations of putting 34,000 lines of Haskell in...
 ABRIDGED VERSION - Joys & frustrations of putting 34,000 lines of Haskell in... ABRIDGED VERSION - Joys & frustrations of putting 34,000 lines of Haskell in...
ABRIDGED VERSION - Joys & frustrations of putting 34,000 lines of Haskell in...Saurabh Nanda
 
A Tour Of Scala
A Tour Of ScalaA Tour Of Scala
A Tour Of Scalafanf42
 
JavaScripts internals #1
JavaScripts internals #1JavaScripts internals #1
JavaScripts internals #1Martin Pernica
 
JavaScript in Object-Oriented Way
JavaScript in Object-Oriented WayJavaScript in Object-Oriented Way
JavaScript in Object-Oriented WayChamnap Chhorn
 
Jsonsaga 100605143125-phpapp02
Jsonsaga 100605143125-phpapp02Jsonsaga 100605143125-phpapp02
Jsonsaga 100605143125-phpapp02Ramamohan Chokkam
 
Ruby on Rails Training - Module 1
Ruby on Rails Training - Module 1Ruby on Rails Training - Module 1
Ruby on Rails Training - Module 1Mark Menard
 
Ruby on Rails (RoR) as a back-end processor for Apex
Ruby on Rails (RoR) as a back-end processor for Apex Ruby on Rails (RoR) as a back-end processor for Apex
Ruby on Rails (RoR) as a back-end processor for Apex Espen Brækken
 
Javascriptbootcamp
JavascriptbootcampJavascriptbootcamp
Javascriptbootcamposcon2007
 
Metaprogramming JavaScript
Metaprogramming  JavaScriptMetaprogramming  JavaScript
Metaprogramming JavaScriptdanwrong
 
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011Nick Sieger
 
WDB005.1 - JavaScript for Java Developers (Lecture 1)
WDB005.1 - JavaScript for Java Developers (Lecture 1)WDB005.1 - JavaScript for Java Developers (Lecture 1)
WDB005.1 - JavaScript for Java Developers (Lecture 1)Igor Khotin
 

Similar to Ruby Xml Mapping (20)

Workin On The Rails Road
Workin On The Rails RoadWorkin On The Rails Road
Workin On The Rails Road
 
Ruby on Rails Presentation
Ruby on Rails PresentationRuby on Rails Presentation
Ruby on Rails Presentation
 
Gemboys
GemboysGemboys
Gemboys
 
Java script core
Java script coreJava script core
Java script core
 
How DSL works on Ruby
How DSL works on RubyHow DSL works on Ruby
How DSL works on Ruby
 
ABRIDGED VERSION - Joys & frustrations of putting 34,000 lines of Haskell in...
 ABRIDGED VERSION - Joys & frustrations of putting 34,000 lines of Haskell in... ABRIDGED VERSION - Joys & frustrations of putting 34,000 lines of Haskell in...
ABRIDGED VERSION - Joys & frustrations of putting 34,000 lines of Haskell in...
 
A Tour Of Scala
A Tour Of ScalaA Tour Of Scala
A Tour Of Scala
 
Ruby on rails
Ruby on railsRuby on rails
Ruby on rails
 
Ruby
RubyRuby
Ruby
 
Scala
ScalaScala
Scala
 
JavaScripts internals #1
JavaScripts internals #1JavaScripts internals #1
JavaScripts internals #1
 
JavaScript in Object-Oriented Way
JavaScript in Object-Oriented WayJavaScript in Object-Oriented Way
JavaScript in Object-Oriented Way
 
Jsonsaga 100605143125-phpapp02
Jsonsaga 100605143125-phpapp02Jsonsaga 100605143125-phpapp02
Jsonsaga 100605143125-phpapp02
 
All of Javascript
All of JavascriptAll of Javascript
All of Javascript
 
Ruby on Rails Training - Module 1
Ruby on Rails Training - Module 1Ruby on Rails Training - Module 1
Ruby on Rails Training - Module 1
 
Ruby on Rails (RoR) as a back-end processor for Apex
Ruby on Rails (RoR) as a back-end processor for Apex Ruby on Rails (RoR) as a back-end processor for Apex
Ruby on Rails (RoR) as a back-end processor for Apex
 
Javascriptbootcamp
JavascriptbootcampJavascriptbootcamp
Javascriptbootcamp
 
Metaprogramming JavaScript
Metaprogramming  JavaScriptMetaprogramming  JavaScript
Metaprogramming JavaScript
 
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
 
WDB005.1 - JavaScript for Java Developers (Lecture 1)
WDB005.1 - JavaScript for Java Developers (Lecture 1)WDB005.1 - JavaScript for Java Developers (Lecture 1)
WDB005.1 - JavaScript for Java Developers (Lecture 1)
 

More from Marc Seeger

DevOps Boston - Heartbleed at Acquia
DevOps Boston - Heartbleed at AcquiaDevOps Boston - Heartbleed at Acquia
DevOps Boston - Heartbleed at AcquiaMarc Seeger
 
The current state of anonymous filesharing
The current state of anonymous filesharingThe current state of anonymous filesharing
The current state of anonymous filesharingMarc Seeger
 
Lunch and learn: Cucumber and Capybara
Lunch and learn: Cucumber and CapybaraLunch and learn: Cucumber and Capybara
Lunch and learn: Cucumber and CapybaraMarc Seeger
 
building blocks of a scalable webcrawler
building blocks of a scalable webcrawlerbuilding blocks of a scalable webcrawler
building blocks of a scalable webcrawlerMarc Seeger
 
Communitygetriebe Android Systementwicklung
Communitygetriebe Android SystementwicklungCommunitygetriebe Android Systementwicklung
Communitygetriebe Android SystementwicklungMarc Seeger
 
Eventdriven I/O - A hands on introduction
Eventdriven I/O - A hands on introductionEventdriven I/O - A hands on introduction
Eventdriven I/O - A hands on introductionMarc Seeger
 
Alternative Infrastucture
Alternative InfrastuctureAlternative Infrastucture
Alternative InfrastuctureMarc Seeger
 
Communitygetriebene Android Systemerweiterungen
Communitygetriebene Android SystemerweiterungenCommunitygetriebene Android Systemerweiterungen
Communitygetriebene Android SystemerweiterungenMarc Seeger
 
Key-Value Stores: a practical overview
Key-Value Stores: a practical overviewKey-Value Stores: a practical overview
Key-Value Stores: a practical overviewMarc Seeger
 
The Dirac Video CoDec
The Dirac Video CoDecThe Dirac Video CoDec
The Dirac Video CoDecMarc Seeger
 
Anonimität - Konzepte und Werkzeuge
Anonimität - Konzepte und WerkzeugeAnonimität - Konzepte und Werkzeuge
Anonimität - Konzepte und WerkzeugeMarc Seeger
 
Security In Dect
Security In DectSecurity In Dect
Security In DectMarc Seeger
 
Social Media in der Unternehmenskommunikation
Social Media in der UnternehmenskommunikationSocial Media in der Unternehmenskommunikation
Social Media in der UnternehmenskommunikationMarc Seeger
 
xDSL, DSLAM & CO
xDSL, DSLAM & COxDSL, DSLAM & CO
xDSL, DSLAM & COMarc Seeger
 
HdM Stuttgart Präsentationstag PPTP VPN WLAN Update
HdM Stuttgart Präsentationstag PPTP VPN WLAN UpdateHdM Stuttgart Präsentationstag PPTP VPN WLAN Update
HdM Stuttgart Präsentationstag PPTP VPN WLAN UpdateMarc Seeger
 

More from Marc Seeger (17)

DevOps Boston - Heartbleed at Acquia
DevOps Boston - Heartbleed at AcquiaDevOps Boston - Heartbleed at Acquia
DevOps Boston - Heartbleed at Acquia
 
The current state of anonymous filesharing
The current state of anonymous filesharingThe current state of anonymous filesharing
The current state of anonymous filesharing
 
Lunch and learn: Cucumber and Capybara
Lunch and learn: Cucumber and CapybaraLunch and learn: Cucumber and Capybara
Lunch and learn: Cucumber and Capybara
 
NoSQL databases
NoSQL databasesNoSQL databases
NoSQL databases
 
building blocks of a scalable webcrawler
building blocks of a scalable webcrawlerbuilding blocks of a scalable webcrawler
building blocks of a scalable webcrawler
 
Communitygetriebe Android Systementwicklung
Communitygetriebe Android SystementwicklungCommunitygetriebe Android Systementwicklung
Communitygetriebe Android Systementwicklung
 
Eventdriven I/O - A hands on introduction
Eventdriven I/O - A hands on introductionEventdriven I/O - A hands on introduction
Eventdriven I/O - A hands on introduction
 
Alternative Infrastucture
Alternative InfrastuctureAlternative Infrastucture
Alternative Infrastucture
 
Communitygetriebene Android Systemerweiterungen
Communitygetriebene Android SystemerweiterungenCommunitygetriebene Android Systemerweiterungen
Communitygetriebene Android Systemerweiterungen
 
Key-Value Stores: a practical overview
Key-Value Stores: a practical overviewKey-Value Stores: a practical overview
Key-Value Stores: a practical overview
 
ZFS
ZFSZFS
ZFS
 
The Dirac Video CoDec
The Dirac Video CoDecThe Dirac Video CoDec
The Dirac Video CoDec
 
Anonimität - Konzepte und Werkzeuge
Anonimität - Konzepte und WerkzeugeAnonimität - Konzepte und Werkzeuge
Anonimität - Konzepte und Werkzeuge
 
Security In Dect
Security In DectSecurity In Dect
Security In Dect
 
Social Media in der Unternehmenskommunikation
Social Media in der UnternehmenskommunikationSocial Media in der Unternehmenskommunikation
Social Media in der Unternehmenskommunikation
 
xDSL, DSLAM & CO
xDSL, DSLAM & COxDSL, DSLAM & CO
xDSL, DSLAM & CO
 
HdM Stuttgart Präsentationstag PPTP VPN WLAN Update
HdM Stuttgart Präsentationstag PPTP VPN WLAN UpdateHdM Stuttgart Präsentationstag PPTP VPN WLAN Update
HdM Stuttgart Präsentationstag PPTP VPN WLAN Update
 

Recently uploaded

Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 

Recently uploaded (20)

Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 

Ruby Xml Mapping

  • 1. Markup Languages und Anwendungen Marc Seeger (20488) mail@marc-seeger.de Computer Science and Media, HdM Stuttgart, WS 08/09
  • 2. Ruby  XML Mapping Libraries  YAML 
  • 3. A language that doesn't affect the way you think about programming, is not worth knowing Alan Perlis
  • 4. Origin:   Yukihiro quot;Matzquot; Matsumoto  Japan 1993 1st english book: 2000  Ruby on Rails: 2004 
  • 5. Variable Declaration:  Function Declaration:  do_something(quot;Marcquot;, 4)  MarcMarcMarc 12
  • 6. ClassNames  method_names and variable_names  methods_asking_a_question?  slightly_dangerous_methods!  @instance_variables  $global_variables  SOME_CONSTANTS or OtherConstants 
  • 7.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13. ?
  • 14. No Primitives, Integers and floats are objects!   -1.abs => 1
  • 16. nil, not null  nil is an object!   nil.nil? => true  nil.class => NilClass nil and false are false   everything else, including 0, is true
  • 17. Expression oriented syntax.   Almost everything returns a value  Methods automatically return their last expression.
  • 18. Single Inheritance   But mixins are available (= Interface with implemented methods)
  • 19.  This module implements the mixin A class that doesn‘t do that much inheriting and mixing! We inherited that one And mixed in that one
  • 20. Classes are always open (even built in classes)  Another Example from Rails: 1.hour.from_now
  • 21.
  • 22. Procedural  Object Oriented  Functional 
  • 23.
  • 24. irb(main):001:0> 42.methods => [quot;%quot;, quot;odd?quot;, quot;inspectquot;, quot;prec_iquot;, quot;<<quot;, quot;tapquot;, quot;divquot;, quot;&quot;, quot;clonequot;, quot;>>quot;, quot;p ublic_methodsquot;, quot;__send__quot;, quot;instance_variable_defined?quot;, quot;equal?quot;, quot;freezequot;, „to_symquot;, quot;*quot;, quot;ordquot;, quot;+quot;, quot;extendquot;, quot;nextquot;, quot;sendquot;, quot;roundquot;, quot;methodsquot;, quot;prec_f„, quot;-quot;, quot;even?quot;, quot;singleton_method_addedquot;, quot;divmodquot;, quot;hashquot;, quot;/quot;, quot;integer?quot;, quot;downtoquot;, quot;dupquot;, quot;instance_variablesquot;, quot;|quot;, quot;eql?quot;, quot;sizequot;, quot;object_idquot;, quot;instance_evalquot;, quot;truncatequot;, quot;~quot;, quot;idquot;, quot;to_iquot;, quot;singleton_methodsquot;, […] irb(main):005:0> nil.class => NilClass irb(main):002:0> nil.hallo_hdm NoMethodError: undefined method `hallo_hdm' for nil:NilClass from (irb):2
  • 25. Strong typing  ▪ quot; 5 quot; / 2  „NoMethodError“ Weak typing  ▪ quot; 16 quot; / 2  8 (e.g. in Perl) Ruby is strongly typed! (Java too)
  • 26. Explicit: int a = 5  Implicit: a = 5  Ruby is implicitly typed! (Java explicitly)
  • 27. Static typing   The compiler checks types during compilation Dynamic typing   The compiler doesn‘t check types during compilation Ruby uses dynamic typing (Java uses static typing)
  • 28. „Blocks are unnamed functions“
  • 30. The current piece of What we are going the collection we are to do with it working with
  • 31. A closure object has: •code to run (the executable) •state around the code (the scope) So you capture the environment, namely the local variables, in the closure. As a result, you can refer to the local variables inside a closure
  • 32. Idea: Function returning a function In action:
  • 33.
  • 34. Ruby VM (Ruby 1.8)  YARV (aka Ruby 1.9)  Rubinius  MacRuby  Jruby  IronRuby  Hotruby 
  • 35. Gem:   Search:  Installing:
  • 36. Gem:   Usage:
  • 37. Enough with the Jibber-Jabber
  • 38. XML  Object   XML-Object  XmlSimple XML  Object   ROXML  XML::MAPPING  HappyMapper
  • 39. http://xml-object.rubyforge.org/ „Tools like JSON or YAML are a much better fit for this kind of job, but one doesn’t always have that luxury.“
  • 40. … attempts to make the accessing of small, well-formed XML structures convenient, by providing a syntax that fits well in most Ruby programs.
  • 41.
  • 42. >ruby test.rb At first, Elements are checked: Bread Recepie You can get the Attributes though: an awesome recepie for bread
  • 43. Question notation enabled?) Elements or attributes that look like booleans are “booleanized” if called by their question names (such as
  • 44. Question notation enabled?) Elements or attributes that look like booleans are “booleanized” if called by their question names (such as
  • 45. Question notation enabled?) Elements or attributes that look like booleans are “booleanized” if called by their question names (such as
  • 46. Question notation enabled?) Elements or attributes that look like booleans are “booleanized” if called by their question names (such as
  • 47. Question notation enabled?) Elements or attributes that look like booleans are “booleanized” if called by their question names (such as
  • 48. Recursive The design of the adapters assumes parsing of the objects recursively. Deep files are bound to throw SystemStackError, but for the kinds of files I need to read, things are working fine so far. In any case, stream parsing is on the TODO list.
  • 49. http://xml-simple.rubyforge.org/ a Ruby translation of Grant McLean's Perl module XML::Simple
  • 50. xml_in()  xml_out() 
  • 51.
  • 52. The input file A hash containing options
  • 54.
  • 56. roxml_1.0_beta roxml-1.0_beta June 28, 2006 ROXML 1.0 roxml-1.0.zip July 1, 2006 September 24, ROXML 1.1 Beta ROXML 1.1 Beta 2006 ROXML 1.2 ROXML 1.2 November 10, 2007 ROXML 2.2.0 November 3, 2008
  • 57. ROXML Features  Read Ruby objects from XML  Write Ruby objects to XML  Annotation-style methods for XML mapping  One-to-one (composition) Ruby to XML  One-to-many (aggregation) Ruby with array to XML Source: http://roxml.rubyforge.org
  • 58.
  • 59.
  • 61. } XML::Mapping::ArrayNode XML::Mapping::BooleanNode XML::Mapping::HashNode XML::Mapping::NumericNode single-attribute nodes XML::Mapping::ObjectNode XML::Mapping::SingleAttributeNode XML::Mapping::SubObjectBaseNode XML::Mapping::TextNode XML::Mapping::ChoiceNode
  • 62.
  • 63. http://happymapper.rubyforge.org/ „Making XML fun again“
  • 65. Camel Case XML Tags to Ruby method names
  • 66.
  • 68. easily readable by humans. 1. matches the native data structures of agile 2. languages. portable between programming languages. 3. consistent model to support generic tools. 4. supports one-pass processing. 5. expressive and extensible. 6. easy to implement and use. 7.
  • 69. JSON/YAML = human readable data interchange format  JSON == simplicity + universality   trivial to generate and parse  reduced human readability YAML == human readability + serializing native data structures   harder to generate and parse  easy to read
  • 70. JSON YAML JSON.valid? YAML.valid!
  • 71. …is Sequences, Maps, Scalars   Seq = Array  Map = Hash  Scalars = String, Integer, Float, Time, NilClass
  • 74. Map of Scalars: Hash of Objects: Native typing is implicity determined in plain scalars.
  • 75.
  • 76. YAML output:  YAML input: 
  • 77.
  • 78. More than 1 document  Ruby code  Output 
  • 79. Won‘t somebody please think of the children objects!
  • 81. Problem: The !ruby/object type is only understood by YAML.rb. Solution:
  • 82. http://www.kuwata-lab.com/kwalify/  YAML and JSON are simple and nice format  for structured data and easier for human to read and write than XML. But there have been no schema for YAML such as RelaxNG or DTD. Kwalify gets over this situation.
  • 84. Each project‘s website  Some useful closures in Ruby  http://www.randomhacks.net/articles/2007/02/01/some-useful-closures-in-ruby Kai Jäger: Ajax in der Praxis Grundlagen, Konzepte, Lösungen  ISBN-10: 3-540-69333-5 Using Ruby - An Introduction to Ruby for Java Programmers  http://onestepback.org/articles/usingruby/index.html Ruby for Java Programmers  http://www.softwaresummit.com/2006/speakers/BowlerRubyForJavaProgrammers.pdf Happy Mapper: Making XML fun again:  http://railstips.org/2008/11/17/happymapper-making-xml-fun-again YAML Working draft 1.2  http://yaml.org/spec/1.2/ YAML Cookbook:  http://www.nt.ntnu.no/users/haugwarb/Programming/YAML/YAML_for_ruby.html