Created
November 17, 2011 14:34
-
-
Save serialseb/1373274 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static IEnumerable<Dictionary<string, string>> ItemScope(this XDocument document, string schema, params string[] propertyNames) | |
{ | |
return from node in document.Document.Descendants() | |
where node.HAttr("itemtype") == schema | |
where node.HAttr("itemscope") == "itemscope" | |
select (from property in node.Descendants() | |
let propName = property.HAttr("itemprop") | |
where propertyNames.Contains(propName) | |
select property).ToDictionary(_=>_.HAttr("itemprop"), _=>_.Value); | |
} | |
public static string GetLinkValue(this WebResponse response, string rel) | |
{ | |
return (from header in response.Headers["Link"].Split(',') | |
let components = header.Split(';') | |
let uri = components[0] | |
where components.Any( | |
component => | |
Regex.IsMatch(component, | |
@"rel\s*=\s*" + Regex.Escape(rel))) | |
select uri.Substring(1, uri.Length - 2)) | |
.FirstOrDefault(); | |
} | |
const string XHTML_NS = "http://www.w3.org/1999/xhtml"; | |
public static string HAttr(this XElement element, string attribName) | |
{ | |
var attrib = element.Attribute(attribName);//XName.Get(attribName, XHTML_NS)); | |
return attrib != null ? attrib.Value : null; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment