Created
November 8, 2018 11:26
-
-
Save RichardD2/d03fb96ca4fa50ca95d5d21fe54c5cd2 to your computer and use it in GitHub Desktop.
XLinq extension methods to select elements using the default namespace of the container.
This file contains hidden or 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; | |
using System.Collections.Generic; | |
using System.Linq; | |
namespace System.Xml.Linq | |
{ | |
public static class XmlDefaultNamespaceExtensions | |
{ | |
public static IEnumerable<XElement> DescendantsNs(this XElement container, string name) | |
=> container.Descendants(container.Name.Namespace + name); | |
public static IEnumerable<XElement> ElementsNs(this XElement container, string name) | |
=> container.Elements(container.Name.Namespace + name); | |
public static XElement ElementNs(this XElement container, string name) | |
=> container.Element(container.Name.Namespace + name); | |
public static IEnumerable<XElement> DescendantsNs(this IEnumerable<XElement> source, string name) | |
=> source.SelectMany(el => DescendantsNs(el, name)); | |
public static IEnumerable<XElement> ElementsNs(this IEnumerable<XElement> source, string name) | |
=> source.SelectMany(el => ElementsNs(el, name)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment