/// <summary> /// /// </summary> /// <param name="entryEl"></param> /// <param name="nsMgr"></param> /// <param name="rel"></param> /// <param name="contentType">e.g. application/atom+xml</param> /// <param name="contentSubType">e.g. "entry"</param> /// <param name="baseUri"></param> /// <returns></returns> public static string GetLink(IXmlNode entryEl, XmlNamespaceManager nsMgr, string rel, string contentType, string contentSubType, Uri baseUri) { Debug.Assert(contentSubType == null || contentType != null, "contentSubType is only used if contentType is also provided"); string xpath = string.Format(CultureInfo.InvariantCulture, @"atom:link[@rel='{0}']", rel); foreach (XmlElement link in entryEl.SelectNodesNS(xpath, nsMgr.ToNSMethodFormat())) { if (contentType != null) { string mimeType = link.GetAttribute("type"); if (mimeType == null || mimeType == "") { continue; } IDictionary mimeData = MimeHelper.ParseContentType(mimeType, true); if (contentType != (string)mimeData[""]) { continue; } if (contentSubType != null && contentSubType != (string)mimeData["type"]) { continue; } } return(XmlHelper.GetUrl(link, "@href", baseUri)); } return(""); }
private static bool AcceptsEntry(string contentType) { IDictionary values = MimeHelper.ParseContentType(contentType, true); string mainType = values[""] as string; switch (mainType) { case "entry": case "*/*": case "application/*": return(true); case "application/atom+xml": string subType = values["type"] as string; if (subType != null) { subType = subType.Trim().ToUpperInvariant(); } if (subType == "ENTRY") { return(true); } else { return(false); } default: return(false); } }
private static bool AcceptsImages(string[] contentTypes) { bool acceptsPng = false, acceptsJpeg = false, acceptsGif = false; foreach (string contentType in contentTypes) { IDictionary values = MimeHelper.ParseContentType(contentType, true); string mainType = values[""] as string; switch (mainType) { case "*/*": case "image/*": return(true); case "image/png": acceptsPng = true; break; case "image/gif": acceptsGif = true; break; case "image/jpeg": acceptsJpeg = true; break; } } return(acceptsPng && acceptsJpeg && acceptsGif); }
private void ParseFeedDoc(XmlDocument xmlDoc, Uri baseUri, bool includeTitle, ref string homepageUrl, ref string title) { if (includeTitle) { XmlElement titleEl = xmlDoc.SelectSingleNode(@"atom:feed/atom:title", _nsMgr) as XmlElement; if (titleEl != null) { title = _atomVer.TextNodeToPlaintext(titleEl); } } foreach (XmlElement linkEl in xmlDoc.SelectNodes(@"atom:feed/atom:link[@rel='alternate']", _nsMgr)) { IDictionary contentTypeInfo = MimeHelper.ParseContentType(linkEl.GetAttribute("type"), true); switch (contentTypeInfo[""] as string) { case "text/html": case "application/xhtml+xml": homepageUrl = XmlHelper.GetUrl(linkEl, "@href", baseUri); return; } } }