Arlen Beiler Arlen Beiler - 2 months ago 27
C# Question

Reading links in header using WebKit.NET

I am trying to figure out how to read header links using C#.NET. I want to get the edit link from Browser1 and put it in browser 2. My problem is that I can't figure out how to get at attributes, or even the link tags for that matter. Below is what I have now.

using System.XML.Linq;
string source = webKitBrowser1.DocumentText.ToString();
XDocument doc = new XDocument(XDocument.Parse(source));

This would work except that xml is different than html, and right off the bat, it says that it was expecting "doctype" to be uppercase.


I finally figured it out, so I will post it for anyone who has the same question.

string site = webKitBrowser1.Url.Scheme + "://" + webKitBrowser1.Url.Authority;
WebKit.DOM.Document doc = webKitBrowser1.Document;
WebKit.DOM.NodeList links = doc.GetElementsByTagName("link");
WebKit.DOM.Element link;
string editlink = "none";
foreach (var item in links)
    link = (WebKit.DOM.Element)item;
    if (link.Attributes["rel"].NodeValue == "edit") { editlink = link.Attributes["href"].NodeValue; }
if (editlink != "none") { webKitBrowser2.Navigate(site + editlink); }