SlideShare a Scribd company logo
1 of 17
Download to read offline
iOS:	
  Web	
  Services	
  and	
  XML	
  Parsing	
  

                 Jussi	
  Pohjolainen	
  
     Tampere	
  University	
  of	
  Applied	
  Sciences	
  
About	
  Web	
  Services	
  
•  Fetch	
  content	
  via	
  HTTP	
  
•  Parse	
  the	
  content	
  
•  Content	
  is	
  usually	
  
    –  XML	
  
    –  JSON	
  
•  Example:	
  weather	
  data,	
  bus	
  traffic	
  
   informaLon,	
  twiMer…	
  
HTTP	
  GET	
  
Fetching	
  content	
  over	
  HTTP	
  
•  In	
  iOS	
  it’s	
  easy	
  to	
  fetch	
  content	
  over	
  HTTP	
  
•  Classes	
  needed	
  
    –  NSURL	
  
    –  NSURLRequest	
  
    –  NSURLConnecLon	
  
•  The	
  NSURLConnecLon	
  has	
  a	
  delegate	
  
   NSURLConnecLonDelegate	
  which	
  holds	
  
   methods	
  like	
  didReceiveData	
  and	
  
   connecLonDidFinishLoading	
  
NSURLConnecLon	
  Example	
  
NSURLConnecLonDelegate	
  
PARSING	
  XML	
  
OpLons	
  
•  SAX	
  
       –  Event	
  driven	
  
       –  Does	
  not	
  consume	
  lot	
  of	
  memory	
  
       –  iOS:	
  NSXMLParser	
  	
  
•  Dom	
  
       –  Reads	
  enLre	
  document	
  to	
  memory	
  
       –  You	
  can	
  move	
  in	
  the	
  object	
  tree	
  
       –  libxml2	
  –	
  C	
  based	
  API	
  for	
  SAX	
  and	
  DOM	
  
	
  
Third	
  Party	
  OpLons	
  
•  TBXML	
  
   –  Lightweight	
  DOM,	
  read	
  only	
  
•  TouchXML	
  
   –  DOM	
  and	
  XPath,	
  read	
  only	
  
•  KissXML	
  
   –  TouchXML	
  +	
  ediLng	
  of	
  xml	
  
•  GDataXML	
  
   –  DOM	
  	
  and	
  Xpath,	
  read	
  and	
  write,	
  developed	
  by	
  
      Google	
  
NSData	
  vs.	
  NSMutableData	
  
•  NSMutableData	
  
   –  Wrapper	
  for	
  byte	
  buffer.	
  Can	
  be	
  modified	
  
•  NSData	
  
   –  Wrapper	
  for	
  byte	
  buffer.	
  Cannot	
  be	
  modified	
  
•  In	
  didReceiveData	
  
Parsing	
  XML	
  Data	
  using	
  NSXMLParser	
  
•  iOS	
  has	
  NSXMLParser	
  for	
  parsing	
  data	
  in	
  an	
  
   event	
  driven	
  way	
  (can	
  be	
  complicated).	
  
•  The	
  NSXMLParser	
  opens	
  xml	
  data	
  and	
  calls	
  
   methods	
  like	
  
    –  didStartElement	
  
    –  foundCharacters	
  
    –  didEndElement	
  
How	
  to	
  start	
  parsing	
  XML?	
  


The	
  NSXMLParserDelegate	
  provides	
  you	
  methods:	
  
JSON	
  
JSON	
  
•  JavaScript	
  Object	
  NotaLon,	
  is	
  a	
  text-­‐based	
  
   open	
  standard	
  designed	
  for	
  human-­‐readable	
  
   data	
  interchange	
  
•  RepresenLng	
  simple	
  data	
  structures	
  and	
  
   associaLve	
  arrays,	
  called	
  objects.	
  
•  Despite	
  its	
  relaLonship	
  to	
  JavaScript,	
  it	
  is	
  
   language-­‐independent,	
  with	
  parsers	
  available	
  
   for	
  many	
  languages.	
  
Example	
  
{
    "response":{
       "version":"0.1",
       "termsofService":"http://www.wunderground.com/weather/api/d/terms.html",
       "features":{
          "conditions":1
       }
    },
    "current_observation":{
       "image":{
          "url":"http://icons-ak.wxug.com/graphics/wu2/logo_130x80.png",
          "title":"Weather Underground",
          "link":"http://www.wunderground.com"
       },
       "display_location":{
          "full":"Tampere, Finland",
          "city":"Tampere",
          "state":"",
          "state_name":"Finland",
          "country":"FI",
          "country_iso3166":"FI",
          "zip":"00000",
          "latitude":"61.41999817",
          "longitude":"23.57999992",
JSON	
  Parsing	
  
•  From	
  iOS	
  5	
  and	
  above,	
  you	
  can	
  do	
  JSON	
  
   parsing	
  using	
  NSJSONSerializaLon	
  
•  Convert	
  JSON	
  to	
  foundaLon	
  objects	
  and	
  back	
  
•  See	
  Doc	
  
   –  hMp://developer.apple.com/library/ios/
      #documentaLon/FoundaLon/Reference/
      NSJSONSerializaLon_Class/Reference/
      Reference.html	
  
Parsing	
  
NSError* errorObject;

// _data (NSData) contains parsable json content
NSDictionary* json =
      [NSJSONSerialization
             JSONObjectWithData: _data
                        options:NSJSONReadingMutableContainers
                           error:&errorObject];
NSDictionary* observation =
   [json objectForKey:@"current_observation"];

NSDictionary* displayLocation =
   [observation objectForKey:@"display_location"];

// “Tampere”
NSString* city =
   [[NSString alloc] initWithFormat:@"%@",
      [displayLocation objectForKey:@"city"]]

More Related Content

What's hot

Mongo Presentation by Metatagg Solutions
Mongo Presentation by Metatagg SolutionsMongo Presentation by Metatagg Solutions
Mongo Presentation by Metatagg SolutionsMetatagg Solutions
 
Electron, databases, and RxDB
Electron, databases, and RxDBElectron, databases, and RxDB
Electron, databases, and RxDBBen Gotow
 
Intro To Mongo Db
Intro To Mongo DbIntro To Mongo Db
Intro To Mongo Dbchriskite
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDBNosh Petigara
 
Back to Basics Webinar 1: Introduction to NoSQL
Back to Basics Webinar 1: Introduction to NoSQLBack to Basics Webinar 1: Introduction to NoSQL
Back to Basics Webinar 1: Introduction to NoSQLMongoDB
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDBAlex Bilbie
 
MongoDB Java Development - MongoBoston 2010
MongoDB Java Development - MongoBoston 2010MongoDB Java Development - MongoBoston 2010
MongoDB Java Development - MongoBoston 2010Eliot Horowitz
 
Comparing JSON Libraries - July 19 2011
Comparing JSON Libraries - July 19 2011Comparing JSON Libraries - July 19 2011
Comparing JSON Libraries - July 19 2011sullis
 
Terrastore - A document database for developers
Terrastore - A document database for developersTerrastore - A document database for developers
Terrastore - A document database for developersSergio Bossa
 
Mongo db – document oriented database
Mongo db – document oriented databaseMongo db – document oriented database
Mongo db – document oriented databaseWojciech Sznapka
 

What's hot (20)

Json
JsonJson
Json
 
Mongo Presentation by Metatagg Solutions
Mongo Presentation by Metatagg SolutionsMongo Presentation by Metatagg Solutions
Mongo Presentation by Metatagg Solutions
 
Mongo db basics
Mongo db basicsMongo db basics
Mongo db basics
 
Mongo-Drupal
Mongo-DrupalMongo-Drupal
Mongo-Drupal
 
Electron, databases, and RxDB
Electron, databases, and RxDBElectron, databases, and RxDB
Electron, databases, and RxDB
 
Intro To Mongo Db
Intro To Mongo DbIntro To Mongo Db
Intro To Mongo Db
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Back to Basics Webinar 1: Introduction to NoSQL
Back to Basics Webinar 1: Introduction to NoSQLBack to Basics Webinar 1: Introduction to NoSQL
Back to Basics Webinar 1: Introduction to NoSQL
 
AJAX
AJAXAJAX
AJAX
 
Mongo db
Mongo dbMongo db
Mongo db
 
Mongo db nosql (1)
Mongo db nosql (1)Mongo db nosql (1)
Mongo db nosql (1)
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
How do i Meet MongoDB
How do i Meet MongoDBHow do i Meet MongoDB
How do i Meet MongoDB
 
Why JSON API?
Why JSON API?Why JSON API?
Why JSON API?
 
MongoDB Java Development - MongoBoston 2010
MongoDB Java Development - MongoBoston 2010MongoDB Java Development - MongoBoston 2010
MongoDB Java Development - MongoBoston 2010
 
Json
JsonJson
Json
 
Comparing JSON Libraries - July 19 2011
Comparing JSON Libraries - July 19 2011Comparing JSON Libraries - July 19 2011
Comparing JSON Libraries - July 19 2011
 
Terrastore - A document database for developers
Terrastore - A document database for developersTerrastore - A document database for developers
Terrastore - A document database for developers
 
Mongo db – document oriented database
Mongo db – document oriented databaseMongo db – document oriented database
Mongo db – document oriented database
 
JSON
JSONJSON
JSON
 

Similar to iOS: Web Services and XML parsing

module 2.pptx for full stack mobile development application on backend applic...
module 2.pptx for full stack mobile development application on backend applic...module 2.pptx for full stack mobile development application on backend applic...
module 2.pptx for full stack mobile development application on backend applic...HemaSenthil5
 
Berlin Buzz Words - Apache Drill by Ted Dunning & Michael Hausenblas
Berlin Buzz Words - Apache Drill by Ted Dunning & Michael HausenblasBerlin Buzz Words - Apache Drill by Ted Dunning & Michael Hausenblas
Berlin Buzz Words - Apache Drill by Ted Dunning & Michael HausenblasMapR Technologies
 
Hdc09 I Phone Dev Connecting To Web
Hdc09   I Phone Dev Connecting To WebHdc09   I Phone Dev Connecting To Web
Hdc09 I Phone Dev Connecting To WebAndy Peters
 
INT 222.pptx
INT 222.pptxINT 222.pptx
INT 222.pptxSaunya2
 
Big Data and Machine Learning with FIWARE
Big Data and Machine Learning with FIWAREBig Data and Machine Learning with FIWARE
Big Data and Machine Learning with FIWAREFernando Lopez Aguilar
 
IPTC News in JSON Spring 2013
IPTC News in JSON Spring 2013IPTC News in JSON Spring 2013
IPTC News in JSON Spring 2013Stuart Myles
 
Consuming RESTful Web services in PHP
Consuming RESTful Web services in PHPConsuming RESTful Web services in PHP
Consuming RESTful Web services in PHPZoran Jeremic
 
Consuming RESTful services in PHP
Consuming RESTful services in PHPConsuming RESTful services in PHP
Consuming RESTful services in PHPZoran Jeremic
 
Cross-Platform Mobile Apps & Drupal Web Services
Cross-Platform Mobile Apps & Drupal Web ServicesCross-Platform Mobile Apps & Drupal Web Services
Cross-Platform Mobile Apps & Drupal Web ServicesBob Sims
 
Speed Up Your APEX Apps with JSON and Handlebars
Speed Up Your APEX Apps with JSON and HandlebarsSpeed Up Your APEX Apps with JSON and Handlebars
Speed Up Your APEX Apps with JSON and HandlebarsMarko Gorički
 
JSON Fuzzing: New approach to old problems
JSON Fuzzing: New  approach to old problemsJSON Fuzzing: New  approach to old problems
JSON Fuzzing: New approach to old problemstitanlambda
 
Attack monitoring using ElasticSearch Logstash and Kibana
Attack monitoring using ElasticSearch Logstash and KibanaAttack monitoring using ElasticSearch Logstash and Kibana
Attack monitoring using ElasticSearch Logstash and KibanaPrajal Kulkarni
 
IPTC News in JSON AGM 2013
IPTC News in JSON AGM 2013IPTC News in JSON AGM 2013
IPTC News in JSON AGM 2013Stuart Myles
 
A Higher-Order Data Flow Model for Heterogeneous Big Data
A Higher-Order Data Flow Model for Heterogeneous Big DataA Higher-Order Data Flow Model for Heterogeneous Big Data
A Higher-Order Data Flow Model for Heterogeneous Big DataSimon Price
 
Json - ideal for data interchange
Json - ideal for data interchangeJson - ideal for data interchange
Json - ideal for data interchangeChristoph Santschi
 

Similar to iOS: Web Services and XML parsing (20)

module 2.pptx for full stack mobile development application on backend applic...
module 2.pptx for full stack mobile development application on backend applic...module 2.pptx for full stack mobile development application on backend applic...
module 2.pptx for full stack mobile development application on backend applic...
 
Berlin Buzz Words - Apache Drill by Ted Dunning & Michael Hausenblas
Berlin Buzz Words - Apache Drill by Ted Dunning & Michael HausenblasBerlin Buzz Words - Apache Drill by Ted Dunning & Michael Hausenblas
Berlin Buzz Words - Apache Drill by Ted Dunning & Michael Hausenblas
 
Json
JsonJson
Json
 
Hdc09 I Phone Dev Connecting To Web
Hdc09   I Phone Dev Connecting To WebHdc09   I Phone Dev Connecting To Web
Hdc09 I Phone Dev Connecting To Web
 
INT 222.pptx
INT 222.pptxINT 222.pptx
INT 222.pptx
 
Big Data and Machine Learning with FIWARE
Big Data and Machine Learning with FIWAREBig Data and Machine Learning with FIWARE
Big Data and Machine Learning with FIWARE
 
Node.js Introduction
Node.js IntroductionNode.js Introduction
Node.js Introduction
 
IPTC News in JSON Spring 2013
IPTC News in JSON Spring 2013IPTC News in JSON Spring 2013
IPTC News in JSON Spring 2013
 
Consuming RESTful Web services in PHP
Consuming RESTful Web services in PHPConsuming RESTful Web services in PHP
Consuming RESTful Web services in PHP
 
Consuming RESTful services in PHP
Consuming RESTful services in PHPConsuming RESTful services in PHP
Consuming RESTful services in PHP
 
Cross-Platform Mobile Apps & Drupal Web Services
Cross-Platform Mobile Apps & Drupal Web ServicesCross-Platform Mobile Apps & Drupal Web Services
Cross-Platform Mobile Apps & Drupal Web Services
 
Speed Up Your APEX Apps with JSON and Handlebars
Speed Up Your APEX Apps with JSON and HandlebarsSpeed Up Your APEX Apps with JSON and Handlebars
Speed Up Your APEX Apps with JSON and Handlebars
 
Xml parsing
Xml parsingXml parsing
Xml parsing
 
JSON Fuzzing: New approach to old problems
JSON Fuzzing: New  approach to old problemsJSON Fuzzing: New  approach to old problems
JSON Fuzzing: New approach to old problems
 
Json
JsonJson
Json
 
Attack monitoring using ElasticSearch Logstash and Kibana
Attack monitoring using ElasticSearch Logstash and KibanaAttack monitoring using ElasticSearch Logstash and Kibana
Attack monitoring using ElasticSearch Logstash and Kibana
 
IPTC News in JSON AGM 2013
IPTC News in JSON AGM 2013IPTC News in JSON AGM 2013
IPTC News in JSON AGM 2013
 
JSON Application
JSON ApplicationJSON Application
JSON Application
 
A Higher-Order Data Flow Model for Heterogeneous Big Data
A Higher-Order Data Flow Model for Heterogeneous Big DataA Higher-Order Data Flow Model for Heterogeneous Big Data
A Higher-Order Data Flow Model for Heterogeneous Big Data
 
Json - ideal for data interchange
Json - ideal for data interchangeJson - ideal for data interchange
Json - ideal for data interchange
 

More from Jussi Pohjolainen

libGDX: Screens, Fonts and Preferences
libGDX: Screens, Fonts and PreferenceslibGDX: Screens, Fonts and Preferences
libGDX: Screens, Fonts and PreferencesJussi Pohjolainen
 
libGDX: User Input and Frame by Frame Animation
libGDX: User Input and Frame by Frame AnimationlibGDX: User Input and Frame by Frame Animation
libGDX: User Input and Frame by Frame AnimationJussi Pohjolainen
 
Intro to Building Android Games using libGDX
Intro to Building Android Games using libGDXIntro to Building Android Games using libGDX
Intro to Building Android Games using libGDXJussi Pohjolainen
 
Advanced JavaScript Development
Advanced JavaScript DevelopmentAdvanced JavaScript Development
Advanced JavaScript DevelopmentJussi Pohjolainen
 
libGDX: Simple Frame Animation
libGDX: Simple Frame AnimationlibGDX: Simple Frame Animation
libGDX: Simple Frame AnimationJussi Pohjolainen
 
libGDX: Simple Frame Animation
libGDX: Simple Frame AnimationlibGDX: Simple Frame Animation
libGDX: Simple Frame AnimationJussi Pohjolainen
 
Implementing a Simple Game using libGDX
Implementing a Simple Game using libGDXImplementing a Simple Game using libGDX
Implementing a Simple Game using libGDXJussi Pohjolainen
 
Building Android games using LibGDX
Building Android games using LibGDXBuilding Android games using LibGDX
Building Android games using LibGDXJussi Pohjolainen
 
Creating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Creating Asha Games: Game Pausing, Orientation, Sensors and GesturesCreating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Creating Asha Games: Game Pausing, Orientation, Sensors and GesturesJussi Pohjolainen
 
Creating Games for Asha - platform
Creating Games for Asha - platformCreating Games for Asha - platform
Creating Games for Asha - platformJussi Pohjolainen
 

More from Jussi Pohjolainen (20)

Moved to Speakerdeck
Moved to SpeakerdeckMoved to Speakerdeck
Moved to Speakerdeck
 
Java Web Services
Java Web ServicesJava Web Services
Java Web Services
 
Box2D and libGDX
Box2D and libGDXBox2D and libGDX
Box2D and libGDX
 
libGDX: Screens, Fonts and Preferences
libGDX: Screens, Fonts and PreferenceslibGDX: Screens, Fonts and Preferences
libGDX: Screens, Fonts and Preferences
 
libGDX: Tiled Maps
libGDX: Tiled MapslibGDX: Tiled Maps
libGDX: Tiled Maps
 
libGDX: User Input and Frame by Frame Animation
libGDX: User Input and Frame by Frame AnimationlibGDX: User Input and Frame by Frame Animation
libGDX: User Input and Frame by Frame Animation
 
Intro to Building Android Games using libGDX
Intro to Building Android Games using libGDXIntro to Building Android Games using libGDX
Intro to Building Android Games using libGDX
 
Advanced JavaScript Development
Advanced JavaScript DevelopmentAdvanced JavaScript Development
Advanced JavaScript Development
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
Introduction to AngularJS
Introduction to AngularJSIntroduction to AngularJS
Introduction to AngularJS
 
libGDX: Scene2D
libGDX: Scene2DlibGDX: Scene2D
libGDX: Scene2D
 
libGDX: Simple Frame Animation
libGDX: Simple Frame AnimationlibGDX: Simple Frame Animation
libGDX: Simple Frame Animation
 
libGDX: Simple Frame Animation
libGDX: Simple Frame AnimationlibGDX: Simple Frame Animation
libGDX: Simple Frame Animation
 
libGDX: User Input
libGDX: User InputlibGDX: User Input
libGDX: User Input
 
Implementing a Simple Game using libGDX
Implementing a Simple Game using libGDXImplementing a Simple Game using libGDX
Implementing a Simple Game using libGDX
 
Building Android games using LibGDX
Building Android games using LibGDXBuilding Android games using LibGDX
Building Android games using LibGDX
 
Android Threading
Android ThreadingAndroid Threading
Android Threading
 
Creating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Creating Asha Games: Game Pausing, Orientation, Sensors and GesturesCreating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Creating Asha Games: Game Pausing, Orientation, Sensors and Gestures
 
Creating Games for Asha - platform
Creating Games for Asha - platformCreating Games for Asha - platform
Creating Games for Asha - platform
 
Intro to Asha UI
Intro to Asha UIIntro to Asha UI
Intro to Asha UI
 

Recently uploaded

Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
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
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
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
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
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
 
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
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 

Recently uploaded (20)

Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.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
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
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 ...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
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
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 

iOS: Web Services and XML parsing

  • 1. iOS:  Web  Services  and  XML  Parsing   Jussi  Pohjolainen   Tampere  University  of  Applied  Sciences  
  • 2. About  Web  Services   •  Fetch  content  via  HTTP   •  Parse  the  content   •  Content  is  usually   –  XML   –  JSON   •  Example:  weather  data,  bus  traffic   informaLon,  twiMer…  
  • 4. Fetching  content  over  HTTP   •  In  iOS  it’s  easy  to  fetch  content  over  HTTP   •  Classes  needed   –  NSURL   –  NSURLRequest   –  NSURLConnecLon   •  The  NSURLConnecLon  has  a  delegate   NSURLConnecLonDelegate  which  holds   methods  like  didReceiveData  and   connecLonDidFinishLoading  
  • 8. OpLons   •  SAX   –  Event  driven   –  Does  not  consume  lot  of  memory   –  iOS:  NSXMLParser     •  Dom   –  Reads  enLre  document  to  memory   –  You  can  move  in  the  object  tree   –  libxml2  –  C  based  API  for  SAX  and  DOM    
  • 9. Third  Party  OpLons   •  TBXML   –  Lightweight  DOM,  read  only   •  TouchXML   –  DOM  and  XPath,  read  only   •  KissXML   –  TouchXML  +  ediLng  of  xml   •  GDataXML   –  DOM    and  Xpath,  read  and  write,  developed  by   Google  
  • 10. NSData  vs.  NSMutableData   •  NSMutableData   –  Wrapper  for  byte  buffer.  Can  be  modified   •  NSData   –  Wrapper  for  byte  buffer.  Cannot  be  modified   •  In  didReceiveData  
  • 11. Parsing  XML  Data  using  NSXMLParser   •  iOS  has  NSXMLParser  for  parsing  data  in  an   event  driven  way  (can  be  complicated).   •  The  NSXMLParser  opens  xml  data  and  calls   methods  like   –  didStartElement   –  foundCharacters   –  didEndElement  
  • 12. How  to  start  parsing  XML?   The  NSXMLParserDelegate  provides  you  methods:  
  • 14. JSON   •  JavaScript  Object  NotaLon,  is  a  text-­‐based   open  standard  designed  for  human-­‐readable   data  interchange   •  RepresenLng  simple  data  structures  and   associaLve  arrays,  called  objects.   •  Despite  its  relaLonship  to  JavaScript,  it  is   language-­‐independent,  with  parsers  available   for  many  languages.  
  • 15. Example   { "response":{ "version":"0.1", "termsofService":"http://www.wunderground.com/weather/api/d/terms.html", "features":{ "conditions":1 } }, "current_observation":{ "image":{ "url":"http://icons-ak.wxug.com/graphics/wu2/logo_130x80.png", "title":"Weather Underground", "link":"http://www.wunderground.com" }, "display_location":{ "full":"Tampere, Finland", "city":"Tampere", "state":"", "state_name":"Finland", "country":"FI", "country_iso3166":"FI", "zip":"00000", "latitude":"61.41999817", "longitude":"23.57999992",
  • 16. JSON  Parsing   •  From  iOS  5  and  above,  you  can  do  JSON   parsing  using  NSJSONSerializaLon   •  Convert  JSON  to  foundaLon  objects  and  back   •  See  Doc   –  hMp://developer.apple.com/library/ios/ #documentaLon/FoundaLon/Reference/ NSJSONSerializaLon_Class/Reference/ Reference.html  
  • 17. Parsing   NSError* errorObject; // _data (NSData) contains parsable json content NSDictionary* json = [NSJSONSerialization JSONObjectWithData: _data options:NSJSONReadingMutableContainers error:&errorObject]; NSDictionary* observation = [json objectForKey:@"current_observation"]; NSDictionary* displayLocation = [observation objectForKey:@"display_location"]; // “Tampere” NSString* city = [[NSString alloc] initWithFormat:@"%@", [displayLocation objectForKey:@"city"]]