tags:

views:

527

answers:

2

I'm using WebKit in a C# application to render a CSS-styled XML document, and I'd like to be able to add DOM elements. How do I get access to the DOM to do this? The problem seems to be that there is no property in the WebKitBrowser class that gives access to the private webView member. Is it possible? Do I need to modify the class to add this? Am I just Doing It Wrong?

A: 

(I cannot comment here for whatever reason, so this is an "answer"...)

How do you use Webkit in your C# application at all? To my knowledge there is no C# wrapper for Webkit. So it may be helpful if you specify what software you're using at all.

LonelyPixel
I use http://sourceforge.net/projects/webkitdotnet/
Dan Ellis
A: 

The WebKit.Net, as of 0.3.0 looks like it does not have access to the codedom. I did something slightly different, I used the WebKit.Net, but I added an HTTP listener to the app, and I set up the control to retrieve the pages from there. In this way I do have access to the posts and callbacks within the same app. The rest I do it with JavaScript on the page it self.

        HttpListener listener;

    public Form1( ) {
        InitializeComponent( );

        listener = new System.Net.HttpListener( );

        listener.Prefixes.Add( "http://*:88/" );
        listener.Start( );
        IAsyncResult result = listener.BeginGetContext( new AsyncCallback(  ListenerCallback ), listener );

    }

    public static void ListenerCallback( IAsyncResult result ) {

    string resp = "<body>test</body";

        HttpListener listener = ( HttpListener )result.AsyncState;

        // Call EndGetContext to complete the asynchronous operation.
        try {
            HttpListenerContext context = listener.EndGetContext( result );
            HttpListenerRequest request = context.Request;

            // Obtain a response object.
            HttpListenerResponse response = context.Response;

            // Construct a response.
            string webpage = request.Url.AbsolutePath.Substring( 1 );
            string responseString = null;
            if ( string.IsNullOrEmpty( webpage ) ) {
                responseString = resp;
            }
            else {
                webpage = webpage.Replace( ".", "_" );
                responseString = webkit_test.Properties.Resources.ResourceManager.GetResourceSet( System.Globalization.CultureInfo.CurrentCulture, true, false ).GetObject( webpage ) as string;
                if ( responseString == null ) {
                    responseString = "<html></html><body> 404 Web Page not Found</body>";
                }
            }
            byte[ ] buffer = System.Text.Encoding.UTF8.GetBytes( responseString );

            // Get a response stream and write the response to it.
            response.ContentType = "text/html; charset=UTF-8";
            response.ContentLength64 = buffer.Length;

            System.IO.Stream output = response.OutputStream;
            output.Write( buffer, 0, buffer.Length );
            output.Flush( );

            // You must close the output stream.
            output.Close( );
            IAsyncResult result1 = listener.BeginGetContext( new AsyncCallback( ListenerCallback ), listener );
        }
        catch { }
    }

Btw. That code will also read the web page from an embbeded resource

JorgeLeo