SlideShare una empresa de Scribd logo
1 de 11
Descargar para leer sin conexión
•                                              XML
                     Jason

               •   XML   element

               •   <element>       </element>

               •   IOS   NSURL, NSURLRequest, URLConnection
                                XML

               •         XML          NSXMLParser
Window-Based Application
                               TopSongs

               UIViewController
                RSSTableViewController
                   XIB
#import <UIKit/UIKit.h>

          @interface TopSongsAppDelegate : NSObject <UIApplicationDelegate> {

          }

          @property (nonatomic, retain) IBOutlet UIWindow *window;

          @end




          #import "TopSongsAppDelegate.h"
          #import "RSSTableViewController.h"

          @implementation TopSongsAppDelegate


          @synthesize window=_window;

          - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
          {
              // Override point for customization after application launch.

                   RSSTableViewController *tvc = [[[RSSTableViewController alloc] initWithStyle:UITableViewStylePlain] autorelease];
                   [self.window setRootViewController:tvc];
                   [self.window makeKeyAndVisible];
                   return YES;
          }
XML                  title element
           title element           entry
title element                               flag

                 #import <UIKit/UIKit.h>


                 @interface RSSTableViewController : UITableViewController <NSXMLParserDelegate> {

                     BOOL waitingForEntryTitle;
                     NSMutableString *titleString;
                     NSMutableArray *songs;
                     NSMutableData *xmlData;
                                                                                                     Song List
                     NSURLConnection *connectionInProgress;

                 }

                 - (void) loadSongs;

                 @end




                                                   XML
-(void) viewWillAppear:(BOOL)animated
                       {                                         TableView
                           [super viewWillAppear:animated];
                           NSLog(@"called in viewWillApear");

                           [self loadSongs];
                       }




     - (void) loadSongs
     {
         [songs removeAllObjects];
         [[self tableView] reloadData];

              NSURL *url = [NSURL URLWithString:@"http://ax.itunes.apple.com/" @"WebObjects/MZStoreServices.woa/ws/RSS/topsongs/" @"limit=10/xml"];


              NSURLRequest *request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:10];

              if(!connectionInProgress) {
                  [connectionInProgress cancel];
                  [connectionInProgress release];

                       [xmlData release];
                       xmlData = [[NSMutableData alloc] init];
                       NSLog(@"called in loadSongs");

                       connectionInProgress = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES];

              }

     }
- (void) connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
          {
              NSLog(@"called in didreceived");
              [xmlData appendData:data];
          }


          - (void) connectionDidFinishLoading:(NSURLConnection *)connection
          {
              NSString *xmlCheck = [[[NSString alloc] initWithData:xmlData encoding:NSUTF8StringEncoding] autorelease];

               NSLog(@"xmlCheck = %@", xmlCheck);

               NSXMLParser *parser = [[NSXMLParser alloc] initWithData:xmlData];

               [parser setDelegate:self];
               [parser parse];                                                              XMLParse           XML
                                                            XML
               [parser release];
               [[self tableView] reloadData];   XML                    songs
          }


          - (void) connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
          {
              [connectionInProgress release];
              connectionInProgress = nil;

               [xmlData release];
               xmlData = nil;

               NSString *errorString = [NSString stringWithFormat:@"Fetch failed: %@", [error localizedDescription]];

              UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:errorString delegate:nil cancelButtonTitle:@"OK"
          destructiveButtonTitle:nil otherButtonTitles:nil];
              [actionSheet showInView:[[self view] window]];
              [actionSheet autorelease];
          }
XML
                                                                       element tag

               -(void) parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName
               namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:
               (NSDictionary *)attributeDict
               {
                   if([elementName isEqual:@"entry"])
                   {
                       NSLog(@"Found a song entry");
                       waitingForEntryTitle = YES;
                   }
                   if([elementName isEqual:@"title"] && waitingForEntryTitle)
                   {
                       NSLog(@"found title!");
                       titleString = [[NSMutableString alloc] init];
                   }
               }

                                                         element tag(<title> string </title>
               - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
               {
                   [titleString appendString:string];
               }

                                                             element tag(<title> string </title>
               -(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName
               namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
               {
                   if([elementName isEqual:@"title"] && waitingForEntryTitle)
                   {
                       NSLog(@"ended title:%@", titleString);
                       [songs addObject:titleString];

                       [titleString release];
                       titleString = nil;
                   }

                   if([elementName isEqual:@"entry"])
                   {
                       NSLog(@"ended a song entry");
                       waitingForEntryTitle = NO;
                   }
               }
TableView DataSource Method

     - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
     {
         return [songs count];
     }


     - (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
     {
         UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCell"];

              if(cell == nil) {
                  cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"UITableViewCell"] autorelease];
              }
              [[cell textLabel] setText:[songs objectAtIndex:[indexPath row]]];

              return cell;
     }
xmlCheck = <?xml version="1.0" encoding="utf-8"?>

               !   <feed xmlns:im="http://itunes.apple.com/rss" xmlns="http://www.w3.org/2005/Atom"
               xml:lang="en">
               !   !   <id>http://ax.itunes.apple.com/WebObjects/MZStoreServices.woa/ws/RSS/topsongs/limit=10/
               xml</id><title>iTunes Store: Top Songs</title><updated>2011-09-30T14:43:55-07:00</updated><link
               rel="alternate" type="text/html" href="http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewTop?
               id=38&amp;popId=1"/><link rel="self" href="http://ax.itunes.apple.com/WebObjects/
               MZStoreServices.woa/ws/RSS/topsongs/limit=10/xml"/><icon>http://phobos.apple.com/favicon.ico</
               icon><author><name>iTunes Store</name><uri>http://www.apple.com/itunes/</uri></
               author><rights>Copyright 2008 Apple Inc.</rights>
<entry>
!   !   !    !   <updated>2011-09-30T14:43:55-07:00</updated>
!   !   !    !
!   !   !    !   !   <id>http://itunes.apple.com/us/album/someone-like-you/id420075073?i=420075185&amp;uo=2</id>
!   !   !    !
!   !   !    !   !   <title>Someone Like You - ADELE</title>
!   !   !    !
!   !   !    !   !
!   !   !    !
!   !   !    !   !   <im:name>Someone Like You</im:name>
!   !   !    !
!   !   !    !   !   <link rel="alternate" type="text/html" href="http://itunes.apple.com/us/album/someone-like-you/id420075073?
i=420075185&amp;uo=2"/>
!   !   !    !
!   !   !    !   !   <im:contentType term="Music" label="Music"><im:contentType term="Track" label="Track"/></im:contentType>
!   !   !    !
!   !   !    !   !   <category term="Pop" scheme="http://itunes.apple.com/us/genre/music-pop/id14?uo=2" label="Pop"/>
!   !   !    !
!   !   !    !   !   <link title="Preview" rel="enclosure" type="audio/x-m4a" href="http://a1.mzstatic.com/us/r1000/051/Music/71/b2/95/
mzi.rsrrzevf.aac.p.m4a" im:assetType="preview"><im:duration>30000</im:duration></link>
!   !   !    !
!   !   !    !   !   <im:artist href="http://itunes.apple.com/us/artist/adele/id262836961?uo=2">ADELE</im:artist>
!   !   !    !
!   !   !    !   !   <im:price amount="1.29000" currency="USD">$1.29</im:price>
!   !   !    !
!   !   !    !   !   <im:image height="55">http://a1.mzstatic.com/us/r1000/014/Music/ea/6f/96/mzi.egqrvlca.55x55-70.jpg</im:image>
!   !   !    !
!   !   !    !   !   <im:image height="60">http://a5.mzstatic.com/us/r1000/014/Music/ea/6f/96/mzi.egqrvlca.60x60-50.jpg</im:image>
!   !   !    !
!   !   !    !   !   <im:image height="170">http://a4.mzstatic.com/us/r1000/014/Music/ea/6f/96/mzi.egqrvlca.170x170-75.jpg</im:image>
!   !   !    !
!   !   !    !   !   <rights>2010 XL Recordings Ltd</rights>
!   !   !    !
!   !   !    !   !   <im:releaseDate label="February 22, 2011">2011-02-22T00:00:00-07:00</im:releaseDate>
!   !   !    !
!   !   !    !   !   <im:collection><im:name>21</im:name><link rel="alternate" type="text/html" href="http://itunes.apple.com/us/album/21/
id420075073?uo=2"/><im:contentType term="Music" label="Music"><im:contentType term="Album" label="Album"/></im:contentType></im:collection>
!   !   !    !
!   !   !    !
!   !   !    !   !   <content type="html">&lt;table border=&quot;0&quot; width=&quot;100%&quot;&gt;
    &lt;tr&gt;
        &lt;td&gt;
            &lt;table border=&quot;0&quot; width=&quot;100%&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot;&gt;
                &lt;tr valign=&quot;top&quot; align=&quot;left&quot;&gt;

                        &lt;td align=&quot;center&quot; width=&quot;166&quot; valign=&quot;top&quot;&gt;
                            &lt;a href=&quot;http://itunes.apple.com/us/album/someone-like-you/id420075073?i=420075185&amp;uo=2&quot;&gt;&lt;img
border=&quot;0&quot; alt=&quot;Someone Like You artwork&quot; src=&quot;http://a4.mzstatic.com/us/r1000/014/Music/ea/6f/96/mzi.egqrvlca.
170x170-75.jpg&quot; /&gt;&lt;/a&gt;
                        &lt;/td&gt;
                        &lt;td width=&quot;10&quot;&gt;&lt;img alt=&quot;&quot; width=&quot;10&quot; height=&quot;1&quot; src=&quot;http://
r.mzstatic.com/images/spacer.gif&quot; /&gt;&lt;/td&gt;
                    !&lt;td width=&quot;95%&quot;&gt;


                        &lt;b&gt;&lt;a href=&quot;http://itunes.apple.com/us/album/someone-like-you/id420075073?
  	    	  	 
i=420075185&amp;uo=2&quot;&gt;Someone Like You&lt;/a&gt;&lt;/b&gt;&lt;br/&gt;

Más contenido relacionado

Último

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
 
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
 
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
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
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
 
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
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
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
 
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
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
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
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
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
 
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
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 

Último (20)

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
 
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...
 
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
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
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
 
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
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 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
 
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
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
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
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
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
 
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 ...
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 

Destacado

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Destacado (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

네트워크(웹서비스연결 Xml파싱) pdf

  • 1.
  • 2. XML Jason • XML element • <element> </element> • IOS NSURL, NSURLRequest, URLConnection XML • XML NSXMLParser
  • 3. Window-Based Application TopSongs UIViewController RSSTableViewController XIB
  • 4. #import <UIKit/UIKit.h> @interface TopSongsAppDelegate : NSObject <UIApplicationDelegate> { } @property (nonatomic, retain) IBOutlet UIWindow *window; @end #import "TopSongsAppDelegate.h" #import "RSSTableViewController.h" @implementation TopSongsAppDelegate @synthesize window=_window; - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. RSSTableViewController *tvc = [[[RSSTableViewController alloc] initWithStyle:UITableViewStylePlain] autorelease]; [self.window setRootViewController:tvc]; [self.window makeKeyAndVisible]; return YES; }
  • 5. XML title element title element entry title element flag #import <UIKit/UIKit.h> @interface RSSTableViewController : UITableViewController <NSXMLParserDelegate> { BOOL waitingForEntryTitle; NSMutableString *titleString; NSMutableArray *songs; NSMutableData *xmlData; Song List NSURLConnection *connectionInProgress; } - (void) loadSongs; @end XML
  • 6. -(void) viewWillAppear:(BOOL)animated { TableView [super viewWillAppear:animated]; NSLog(@"called in viewWillApear"); [self loadSongs]; } - (void) loadSongs { [songs removeAllObjects]; [[self tableView] reloadData]; NSURL *url = [NSURL URLWithString:@"http://ax.itunes.apple.com/" @"WebObjects/MZStoreServices.woa/ws/RSS/topsongs/" @"limit=10/xml"]; NSURLRequest *request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:10]; if(!connectionInProgress) { [connectionInProgress cancel]; [connectionInProgress release]; [xmlData release]; xmlData = [[NSMutableData alloc] init]; NSLog(@"called in loadSongs"); connectionInProgress = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES]; } }
  • 7. - (void) connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { NSLog(@"called in didreceived"); [xmlData appendData:data]; } - (void) connectionDidFinishLoading:(NSURLConnection *)connection { NSString *xmlCheck = [[[NSString alloc] initWithData:xmlData encoding:NSUTF8StringEncoding] autorelease]; NSLog(@"xmlCheck = %@", xmlCheck); NSXMLParser *parser = [[NSXMLParser alloc] initWithData:xmlData]; [parser setDelegate:self]; [parser parse]; XMLParse XML XML [parser release]; [[self tableView] reloadData]; XML songs } - (void) connection:(NSURLConnection *)connection didFailWithError:(NSError *)error { [connectionInProgress release]; connectionInProgress = nil; [xmlData release]; xmlData = nil; NSString *errorString = [NSString stringWithFormat:@"Fetch failed: %@", [error localizedDescription]]; UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:errorString delegate:nil cancelButtonTitle:@"OK" destructiveButtonTitle:nil otherButtonTitles:nil]; [actionSheet showInView:[[self view] window]]; [actionSheet autorelease]; }
  • 8. XML element tag -(void) parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes: (NSDictionary *)attributeDict { if([elementName isEqual:@"entry"]) { NSLog(@"Found a song entry"); waitingForEntryTitle = YES; } if([elementName isEqual:@"title"] && waitingForEntryTitle) { NSLog(@"found title!"); titleString = [[NSMutableString alloc] init]; } } element tag(<title> string </title> - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string { [titleString appendString:string]; } element tag(<title> string </title> -(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName { if([elementName isEqual:@"title"] && waitingForEntryTitle) { NSLog(@"ended title:%@", titleString); [songs addObject:titleString]; [titleString release]; titleString = nil; } if([elementName isEqual:@"entry"]) { NSLog(@"ended a song entry"); waitingForEntryTitle = NO; } }
  • 9. TableView DataSource Method - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [songs count]; } - (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCell"]; if(cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"UITableViewCell"] autorelease]; } [[cell textLabel] setText:[songs objectAtIndex:[indexPath row]]]; return cell; }
  • 10. xmlCheck = <?xml version="1.0" encoding="utf-8"?> ! <feed xmlns:im="http://itunes.apple.com/rss" xmlns="http://www.w3.org/2005/Atom" xml:lang="en"> ! ! <id>http://ax.itunes.apple.com/WebObjects/MZStoreServices.woa/ws/RSS/topsongs/limit=10/ xml</id><title>iTunes Store: Top Songs</title><updated>2011-09-30T14:43:55-07:00</updated><link rel="alternate" type="text/html" href="http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewTop? id=38&amp;popId=1"/><link rel="self" href="http://ax.itunes.apple.com/WebObjects/ MZStoreServices.woa/ws/RSS/topsongs/limit=10/xml"/><icon>http://phobos.apple.com/favicon.ico</ icon><author><name>iTunes Store</name><uri>http://www.apple.com/itunes/</uri></ author><rights>Copyright 2008 Apple Inc.</rights>
  • 11. <entry> ! ! ! ! <updated>2011-09-30T14:43:55-07:00</updated> ! ! ! ! ! ! ! ! ! <id>http://itunes.apple.com/us/album/someone-like-you/id420075073?i=420075185&amp;uo=2</id> ! ! ! ! ! ! ! ! ! <title>Someone Like You - ADELE</title> ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! <im:name>Someone Like You</im:name> ! ! ! ! ! ! ! ! ! <link rel="alternate" type="text/html" href="http://itunes.apple.com/us/album/someone-like-you/id420075073? i=420075185&amp;uo=2"/> ! ! ! ! ! ! ! ! ! <im:contentType term="Music" label="Music"><im:contentType term="Track" label="Track"/></im:contentType> ! ! ! ! ! ! ! ! ! <category term="Pop" scheme="http://itunes.apple.com/us/genre/music-pop/id14?uo=2" label="Pop"/> ! ! ! ! ! ! ! ! ! <link title="Preview" rel="enclosure" type="audio/x-m4a" href="http://a1.mzstatic.com/us/r1000/051/Music/71/b2/95/ mzi.rsrrzevf.aac.p.m4a" im:assetType="preview"><im:duration>30000</im:duration></link> ! ! ! ! ! ! ! ! ! <im:artist href="http://itunes.apple.com/us/artist/adele/id262836961?uo=2">ADELE</im:artist> ! ! ! ! ! ! ! ! ! <im:price amount="1.29000" currency="USD">$1.29</im:price> ! ! ! ! ! ! ! ! ! <im:image height="55">http://a1.mzstatic.com/us/r1000/014/Music/ea/6f/96/mzi.egqrvlca.55x55-70.jpg</im:image> ! ! ! ! ! ! ! ! ! <im:image height="60">http://a5.mzstatic.com/us/r1000/014/Music/ea/6f/96/mzi.egqrvlca.60x60-50.jpg</im:image> ! ! ! ! ! ! ! ! ! <im:image height="170">http://a4.mzstatic.com/us/r1000/014/Music/ea/6f/96/mzi.egqrvlca.170x170-75.jpg</im:image> ! ! ! ! ! ! ! ! ! <rights>2010 XL Recordings Ltd</rights> ! ! ! ! ! ! ! ! ! <im:releaseDate label="February 22, 2011">2011-02-22T00:00:00-07:00</im:releaseDate> ! ! ! ! ! ! ! ! ! <im:collection><im:name>21</im:name><link rel="alternate" type="text/html" href="http://itunes.apple.com/us/album/21/ id420075073?uo=2"/><im:contentType term="Music" label="Music"><im:contentType term="Album" label="Album"/></im:contentType></im:collection> ! ! ! ! ! ! ! ! ! ! ! ! ! <content type="html">&lt;table border=&quot;0&quot; width=&quot;100%&quot;&gt; &lt;tr&gt; &lt;td&gt; &lt;table border=&quot;0&quot; width=&quot;100%&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot;&gt; &lt;tr valign=&quot;top&quot; align=&quot;left&quot;&gt; &lt;td align=&quot;center&quot; width=&quot;166&quot; valign=&quot;top&quot;&gt; &lt;a href=&quot;http://itunes.apple.com/us/album/someone-like-you/id420075073?i=420075185&amp;uo=2&quot;&gt;&lt;img border=&quot;0&quot; alt=&quot;Someone Like You artwork&quot; src=&quot;http://a4.mzstatic.com/us/r1000/014/Music/ea/6f/96/mzi.egqrvlca. 170x170-75.jpg&quot; /&gt;&lt;/a&gt; &lt;/td&gt; &lt;td width=&quot;10&quot;&gt;&lt;img alt=&quot;&quot; width=&quot;10&quot; height=&quot;1&quot; src=&quot;http:// r.mzstatic.com/images/spacer.gif&quot; /&gt;&lt;/td&gt; !&lt;td width=&quot;95%&quot;&gt; &lt;b&gt;&lt;a href=&quot;http://itunes.apple.com/us/album/someone-like-you/id420075073? i=420075185&amp;uo=2&quot;&gt;Someone Like You&lt;/a&gt;&lt;/b&gt;&lt;br/&gt;