This repository was archived by the owner on Jun 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathXmlExtensions.cs
More file actions
38 lines (37 loc) · 1.3 KB
/
XmlExtensions.cs
File metadata and controls
38 lines (37 loc) · 1.3 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
using System;
using System.Xml.Linq;
namespace GitMerger
{
public static class XmlExtensions
{
public static string AttributeValue(this XElement element, XName name)
{
if (element == null)
throw new ArgumentNullException(nameof(element), $"{nameof(element)} is null.");
var attribute = element.Attribute(name);
return attribute?.Value ?? string.Empty;
}
public static XElement ElementPath(this XElement element, params XName[] names)
{
if (element == null)
throw new ArgumentNullException(nameof(element), $"{nameof(element)} is null.");
foreach (XName name in names)
{
element = element.Element(name);
if (element == null)
break;
}
return element;
}
public static string ElementValue(this XElement element, params XName[] names)
{
var targetElement = element.ElementPath(names);
return targetElement?.Value ?? string.Empty;
}
public static string ElementValue(this XElement element, XName name)
{
var targetElement = element.Element(name);
return targetElement?.Value ?? string.Empty;
}
}
}