• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: can't get DOMDocument from WebView
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: can't get DOMDocument from WebView


  • Subject: Re: can't get DOMDocument from WebView
  • From: "James G. Speth" <email@hidden>
  • Date: Fri, 19 May 2006 04:18:48 -0700

try this one...

WebView *webView = [[WebView alloc] init];
DOMDocument *document = [[webView windowScriptObject] evaluateWebScript:@"document"];


there you go.. .one nice, fresh, empty DOMHTMLDocument to play with, no waiting on runloops.
(evaluating the javascript for the document makes it take a different code path, one that causes it to initialize the DOMDocument)


you can do [[document documentElement] outerHTML] and see that it contains "<HTML><BODY></BODY></HTML>"
if you do [[[document documentElement] firstChild] setInnerHTML:myStringOfHTML] it'll parse the string and fill in the body element with the appropriate nodes.


cheers!
Jim

On May 2, 2006, at 4:30 PM, Kenny Leung wrote:

Like I said in my original post, I don't actually want to display the HTML. I want to do the relatively simpler task of parsing the HTML into a DOM tree. I don't see where I can do that without loading up a WebView. Any pointers would be much appreciated.

Thanks!

-Kenny


On May 2, 2006, at 4:19 PM, John Stiles wrote:

I think you're trivializing things a bit. Typical uses of an HTML view involve asynchronous data loading which, naturally, is based on the run loop.


On May 2, 2006, at 4:14 PM, Kenny Leung wrote:

Hmmm... It seems that there is no way to get the document to load without returning to the run loop. This makes life difficult. Funny how they designed the system to do something difficult but then made it very difficult to do something very simple. Reminds me of Java.

-Kenny


On May 2, 2006, at 2:20 PM, glenn andreas wrote:


On May 2, 2006, at 4:09 PM, Kenny Leung wrote:

Hi All.

I've been working all morning trying to get A DOM Document from a WebView. Actually, I don't want to use a WebView. I just want to gain access to the DOM parsing functionality. I would be happy if I could get it without instantiating a WebView. Here is the code I've been using, complete with temporary hacks:

self = [super init];
if ( self ) {
window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 100, 100) styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO];
webView = [[[WebView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100)] autorelease];
[window setContentView:webView];
[window makeKeyAndOrderFront:self];
frame = [webView mainFrame];
request = [NSURLRequest requestWithURL:[NSURL fileURLWithPath:path]];
data = [NSData dataWithContentsOfFile:path];
// [frame loadRequest:request];
string = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
[frame loadHTMLString:string baseURL:[NSURL URLWithString:@"http://www.quickceph.com";]];
// while ( ![frame dataSource] ) {
sleep(1);
// }
domDoc = [frame DOMDocument];
}



Everything checks out (not nil) until it gets to the last line of asking for the DOMDocument. The DOMDocument is nil. Has anyone else been successful at this?

Your "while (![frame dataSource]) sleep(1);" does not do what you think it does (regardless of how it is commented or not).


You need to set a load delegate to the web view and implement the webView:didFinishLoadForFrame: routine to actually be notified when the frame is fully loaded (at which point you can do whatever you want with the DOMDocument)


Glenn Andreas email@hidden <http://www.gandreas.com/> wicked fun! Widgetarium | the quickest path to widgets



_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40blizzard.com


This email sent to email@hidden



_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden

_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: can't get DOMDocument from WebView
      • From: Kenny Leung <email@hidden>
References: 
 >can't get DOMDocument from WebView (From: Kenny Leung <email@hidden>)
 >Re: can't get DOMDocument from WebView (From: glenn andreas <email@hidden>)
 >Re: can't get DOMDocument from WebView (From: Kenny Leung <email@hidden>)
 >Re: can't get DOMDocument from WebView (From: John Stiles <email@hidden>)
 >Re: can't get DOMDocument from WebView (From: Kenny Leung <email@hidden>)

  • Prev by Date: Core Data: changes from second MOC not visible main MOC array controller.
  • Next by Date: Re: Right way to check system version?
  • Previous by thread: Re: can't get DOMDocument from WebView
  • Next by thread: Re: can't get DOMDocument from WebView
  • Index(es):
    • Date
    • Thread