/// <summary> /// Try to extract the EditUri (RSD file URI) from the passed DOM /// </summary> /// <param name="weblogDOM"></param> /// <returns></returns> private static string ExtractEditUri(string homepageUrl, IHTMLDocument2 weblogDOM) { // look in the first HEAD tag IHTMLElementCollection headElements = ((IHTMLDocument3)weblogDOM).getElementsByTagName("HEAD"); if (headElements.length > 0) { // get the first head element IHTMLElement2 firstHeadElement = (IHTMLElement2)headElements.item(0, 0); // look for link tags within the head foreach (IHTMLElement element in firstHeadElement.getElementsByTagName("LINK")) { IHTMLLinkElement linkElement = element as IHTMLLinkElement; if (linkElement != null) { string linkRel = linkElement.rel; if (linkRel != null && (linkRel.ToUpperInvariant().Equals("EDITURI"))) { return(UrlHelper.UrlCombineIfRelative(homepageUrl, linkElement.href)); } } } } // couldn't find one return(null); }
public static string DiscoverUrl(string homepageUrl, IHTMLDocument2 weblogDOM) { if (weblogDOM == null) { return(String.Empty); } try { // look in the first HEAD tag IHTMLElementCollection headElements = ((IHTMLDocument3)weblogDOM).getElementsByTagName("HEAD"); if (headElements.length > 0) { // get the first head element IHTMLElement2 firstHeadElement = (IHTMLElement2)headElements.item(0, 0); // look for link tags within the head foreach (IHTMLElement element in firstHeadElement.getElementsByTagName("LINK")) { IHTMLLinkElement linkElement = element as IHTMLLinkElement; if (linkElement != null) { string linkRel = linkElement.rel; if (linkRel != null && (linkRel.ToUpperInvariant().Equals("WLWMANIFEST"))) { if (linkElement.href != null && linkElement.href != String.Empty) { return(UrlHelper.UrlCombineIfRelative(homepageUrl, linkElement.href)); } } } } } } catch (Exception ex) { Trace.Fail("Unexpected error attempting to discover manifest URL: " + ex.ToString()); } // couldn't find one return(String.Empty); }