2

I have a string of HTML that was parsed by libxml2.dylib that looks like:

Hello,<br />\n<br />\nThis is almost HTML.<br />\n<br />\n

I've unsuccessfully tried to display certain strings parsed from the XML in a WebView; I'm hoping there's a simple way to do it such as how an HTML page is displayed in my Cocoa application:

HTMLView.h

#import <Foundation/Foundation.h>
#import <Cocoa/Cocoa.h>
#import <WebKit/WebKit.h>

@interface htmlView : NSObject {

    IBOutlet WebView * webview;
}

-(IBAction) showHTML:(id) sender;

@end

HTMLView.m

#import "HTMLView.h"

@implementation htmlView

-(IBAction) showHTML:(id) sender

{
    [[webview mainFrame] loadRequest:
     [NSURLRequest requestWithURL:
      [NSURL URLWithString:@"http://www.example.com"]]];

 NSString * string = @"<br>test</br>";

[self loadHTMLString:string baseURL:(NSURL *)baseURL];

}
-(void)loadHTMLString:(NSString *)string baseURL:(NSURL *)baseURL {

}

@end

2 Answers 2

4

try this... [[aWebView mainFrame] loadHTMLString:aString baseURL:nil];

Sign up to request clarification or add additional context in comments.

Comments

1

I've unsuccessfully tried to display certain strings parsed from the XML in a WebView

How did you try to display the strings and what was the problem? I think

-(void)loadHTMLString:(NSString *)string baseURL:(NSURL *)baseURL

Might be what you need...!?

Edit: You have to call the method on your webview! What you did now is implementing your own loadHTMLString method in your viewController. Which would be fine if it did anything and did call loadHTMLString on the webview at some point.

[self.webView loadHTMLString....]

I think you have to familiarise yourself a bit more with objective-c.

2 Comments

I tried that using this example (stackoverflow.com/questions/8456088/…), although I must not be using it correctly?
Well, how did you do it? Edit your question and show what you did

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.