-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathXmlUtils.cs
44 lines (43 loc) · 1.33 KB
/
XmlUtils.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
using System;
using System.Xml;
namespace FSClient {
class XmlUtils {
public static String GetNodeAttrib(XmlNode node, String name) {
if (node.Attributes[name] == null)
return "";
return node.Attributes[name].Value;
}
public static String GetNodeValue(XmlNode node, String name) {
if (node.SelectSingleNode(name) == null)
return "";
return node.SelectSingleNode(name).InnerText;
}
public static XmlDocument GetDocument(String xml) {
XmlDocument doc = new XmlDocument();
doc.LoadXml(xml);
return doc;
}
public static XmlNode GetNode(XmlDocument doc, String name, int num) {
XmlNodeList res = doc.GetElementsByTagName(name);
if (res.Count <= num)
return null;
return res[num];
}
public static String GetValue(XmlDocument doc, String name, int num) {
XmlNode node = GetNode(doc, name, num);
if (node == null)
return "";
return node.InnerText;
}
public static void AddNodeAttrib(XmlNode node, String name, String value) {
XmlAttribute attrib = node.OwnerDocument.CreateAttribute(name);
attrib.Value = value;
node.Attributes.Append(attrib);
}
public static XmlNode AddNodeNode(XmlNode node, String name) {
XmlNode new_node = node.OwnerDocument.CreateElement(name);
node.AppendChild(new_node);
return new_node;
}
}
}