Note that there are some explanatory texts on larger screens.

plurals
  1. POUIWebView not showing parsed XML data
    text
    copied!<p>I have a tag <code>&lt;AboutUs&gt;</code> (having HTML tags) and I have stored the string part in a local string. Now I want to pass it to my webView to display, but it is showing my string (<code>null</code>).</p> <p>Here's my code, any help is appreciated:</p> <pre><code>@class AppDelegate_iPhone; @interface AboutUsViewController : UIViewController&lt;NSXMLParserDelegate&gt; { NSMutableString *aboutUsString; NSString *currentElement; IBOutlet UIWebView *webView; AppDelegate_iPhone *appDelegate; } @property(nonatomic,retain) NSMutableString *aboutUsString; @property(nonatomic,retain) IBOutlet UIWebView *webView; -(id)init; @end @implementation AboutUsViewController @synthesize aboutUsString,webView; -(id)init{ if(self == [super init]){ aboutUsString = [[NSMutableString alloc]init]; } return self; } // Implement viewDidLoad to do additional setup after loading the view, typically from a nib. - (void)viewDidLoad { [super viewDidLoad]; appDelegate = (AppDelegate_iPhone *)[[UIApplication sharedApplication] delegate]; NSURL *url = [[NSURL alloc] initWithString:@"http://mobileecommerce.site247365.com/admin/AboutUs.xml"]; NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithContentsOfURL:url]; //Initialize the delegate. AboutUsViewController *parser = [[AboutUsViewController alloc] init]; //Set delegate [xmlParser setDelegate:parser]; //Start parsing the XML file. BOOL success = [xmlParser parse]; if(success) NSLog(@"No Errors"); else NSLog(@"Error Error Error!!!"); NSLog(@"After Parsing=== = = = = = = = == = = = = %@",appDelegate.TextString); } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return YES; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } - (void)viewDidUnload { [super viewDidUnload]; } - (void)parserDidStartDocument:(NSXMLParser *)parser { } - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict { currentElement = elementName; if([currentElement isEqualToString:@"AboutUs"]) { } } - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string { if([currentElement isEqualToString:@"AboutUs"]) { NSMutableString *outputBuilder = [[NSMutableString alloc]init] ; [outputBuilder appendString:[NSString stringWithFormat:@"%@", self.aboutUsString]]; [outputBuilder appendString:[NSString stringWithFormat:@"%@", string]]; self.aboutUsString = outputBuilder; [outputBuilder release]; } else { self.aboutUsString = string; } } - (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName { if([elementName isEqualToString:@"AboutUs"]) { [webView setScalesPageToFit:YES]; [webView loadHTMLString:self.aboutUsString baseURL:[NSURL URLWithString:@"http://www.hitchhiker.com/message"]]; NSLog(@"In DID End Element ===== %@",aboutUsString); appDelegate.TextString = [[NSMutableString alloc]initWithString:aboutUsString]; } currentElement = @""; } - (void)parserDidEndDocument:(NSXMLParser *)parser { NSLog(@"In Document End ========= %@",aboutUsString); NSLog(@"Appdelgate Text String %@",appDelegate.TextString); } - (void)dealloc { [super dealloc]; [webView release]; } @end </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload