-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathXDocumentExtensions.cs
More file actions
82 lines (70 loc) · 3.14 KB
/
Copy pathXDocumentExtensions.cs
File metadata and controls
82 lines (70 loc) · 3.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
namespace Extensions
{
public static class XDocumentExtensions
{
public static IEnumerable<XElement> FilterByNameCaseInsensitive(this IEnumerable<XElement> elements, XName name)
{
return elements
.Where(e => e.Name.Namespace == name.Namespace
&&
e.Name.LocalName.Equals(name.LocalName, StringComparison.OrdinalIgnoreCase));
}
public static IEnumerable<XAttribute> FilterByNameCaseInsensitive(this IEnumerable<XAttribute> attributes, XName name)
{
return attributes
.Where(e => e.Name.Namespace == name.Namespace
&&
e.Name.LocalName.Equals(name.LocalName, StringComparison.OrdinalIgnoreCase));
}
#region System.Xml.Linq.XContainer Methods
public static IEnumerable<XElement> ElementsCaseInsensitive(this XContainer source, XName name)
{
return source.Elements().FilterByNameCaseInsensitive(name);
}
public static XElement ElementCaseInsensitive(this XContainer source, XName name)
{
return source.Elements().FilterByNameCaseInsensitive(name).SingleOrDefault();
}
public static IEnumerable<XElement> DescendantsCaseInsensitive(this XContainer source, XName name)
{
return source.Descendants().FilterByNameCaseInsensitive(name);
}
#endregion
#region System.Xml.Linq.XNode Methods
public static IEnumerable<XElement> AncestorsCaseInsensitive(this XNode source, XName name)
{
return source.Ancestors().FilterByNameCaseInsensitive(name);
}
public static IEnumerable<XElement> ElementsAfterSelfCaseInsensitive(this XNode source, XName name)
{
return source.ElementsAfterSelf().FilterByNameCaseInsensitive(name);
}
public static IEnumerable<XElement> ElementsBeforeSelfCaseInsensitive(this XNode source, XName name)
{
return source.ElementsBeforeSelf().FilterByNameCaseInsensitive(name);
}
#endregion
#region System.Xml.Linq.XElement Methods
public static IEnumerable<XElement> AncestorsAndSelfCaseInsensitive(this XElement source, XName name)
{
return source.AncestorsAndSelf().FilterByNameCaseInsensitive(name);
}
public static IEnumerable<XElement> DescendantsAndSelfCaseInsensitive(this XElement source, XName name)
{
return source.DescendantsAndSelf().FilterByNameCaseInsensitive(name);
}
public static IEnumerable<XAttribute> AttributesCaseInsensitive(this XElement source, XName name)
{
return source.Attributes().FilterByNameCaseInsensitive(name);
}
public static XAttribute AttributeCaseInsensitive(this XElement source, XName name)
{
return source.Attributes().FilterByNameCaseInsensitive(name).SingleOrDefault();
}
#endregion
}
}