Skip to content
slowgreenturtle edited this page Jul 26, 2012 · 2 revisions

Parse XML data from a remote server

TBXML asynchronously retrieves data from a remote server and uses blocks to notify you of a success or failure.

   // Create a success block to be called when the async request completes
   TBXMLSuccessBlock successBlock = ^(TBXML *tbxmlDocument) {
      // If TBXML found a root node, process element and iterate all children
      if (tbxmlDocument.rootXMLElement)
         [self traverseElement:tbxmlDocument.rootXMLElement];
   };
      
   // Create a failure block that gets called if something goes wrong
   TBXMLFailureBlock failureBlock = ^(TBXML *tbxmlDocument, NSError * error) {
      NSLog(@"Error! %@ %@", [error localizedDescription], [error userInfo]);
   };
   
   // Initialize TBXML with the URL of an XML doc. TBXML asynchronously loads and parses the file.
   TBXML *tbxml = [[TBXML alloc] initWithURL:[NSURL URLWithString:@"http://www.w3schools.com/XML/note.xml"] 
                              success:successBlock 
                              failure:failureBlock];
Clone this wiki locally