Created
January 18, 2017 11:36
-
-
Save lavn0/38ebb8823d29c056d1c0b108e28e2a8b 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
using System.Collections.Generic; | |
using System.Linq; | |
using System.Xml.Linq; | |
namespace System.Xml.XPath | |
{ | |
public static class XPathUtility | |
{ | |
public static IEnumerable<T> XPathSelectElements<T>(this XNode xNode, string xpath) | |
where T : XObject | |
{ | |
return ((IEnumerable<object>)xNode.XPathEvaluate(xpath)).Cast<T>(); | |
} | |
public static string GetValue(this XObject xObject) | |
{ | |
return | |
xObject is XAttribute | |
? ((XAttribute)xObject).Value : | |
xObject is XText | |
? ((XText)xObject).Value | |
: ((XElement)xObject).Value; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment