Re: Parsing XML in a web view
Re: Parsing XML in a web view
- Subject: Re: Parsing XML in a web view
- From: Rush Manbert <email@hidden>
- Date: Thu, 07 Sep 2006 10:47:42 -0700
a.d. jensen wrote:
I've put together a small web viewer application that gets information
from a web site, and then passes it off as an AppleEvent to another
application.
The guy who's doing the web end of things wants to pass me that
information as an XML tag, buried in the HTML source of the page that
I'm displaying to the end user, to indicate that their transaction is
complete.
That's all well and good, but I'm at a loss as to:
a) How to access the source of a page, given a webview
b) How to parse said source for the value, buried between XML tags
eg: <fieldValue>Value to parse</fieldValue>
Any pointers to the right Cocoa class or supportive documentation would
be appreciated, thanks!
Hi Dale,
Here's the code I use to get the page source (which someone kindly
showed me on the WebKit list):
- (NSString *)getTextRepresentation
{
WebDataSource *dataSource = [[webView mainFrame] dataSource];
if ([[dataSource representation] canProvideDocumentSource])
{
return [NSString stringWithString:[[dataSource representation]
documentSource]];
}
else
{
return [NSString stringWithCString:"Cannot get text
representation" encoding:NSASCIIStringEncoding];
}
}
However, you probably don't want to get the source and parse it. It's
better to access the DOM, because it has already parsed the source and
built the element tree. From there it should be easy to access the
content within the fieldValue element. I'm afraid that I have no
experience doing this in Cocoa, but if you search the WebKit list for
references to DOM you should find something useful.
- Rush
OT - P.S. Nice sig. Echolyn rules!
_______________________________________________
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