Advantages of Hiring UIUX Design Service Providers for Your Business
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.
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