-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathXElem.cs
84 lines (71 loc) · 2.16 KB
/
XElem.cs
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
83
84
namespace MicroFramework.Xml
{
using System;
public class XElem
{
public string Name { get; set; }
public string Value { get; set; }
public XAttributeList Attributes { get; set; }
public XElemList Children { get; set; }
public XElem()
{
this.Name = string.Empty;
this.Value = string.Empty;
}
internal void AddChild(XElem node)
{
if (this.Children == null)
{
this.Children = new XElemList();
}
this.Children.Add(node);
}
public bool HasChildren { get { return (this.Children != null) && (this.Children.Count > 0); } }
public XElem Element(string elemName)
{
if (this.HasChildren)
{
foreach (XElem elem in this.Children)
{
if (elem.Name.Equals(elemName))
{
return elem;
}
}
}
return null;
}
public XElemList Elements(string elemName)
{
var result = new XElemList();
if (this.HasChildren)
{
foreach (XElem elem in this.Children)
{
if (elem.Name.Equals(elemName))
{
result.Add(elem);
}
}
}
return result;
}
public XElemList Elements()
{
var result = new XElemList();
foreach (XElem elem in this.Children)
{
result.Add(elem);
}
return result;
}
public XAttribute Attribute(string attrName)
{
return this.Attributes[attrName] as XAttribute;
}
public override string ToString()
{
return this.Name + (this.HasChildren ? " (" + this.Children.Count + " children)" : (this.Value.Length > 0) ? " = '" + this.Value + "'" : string.Empty);
}
}
}