forked from fdorg/flashdevelop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathXmlHelper.cs
More file actions
74 lines (67 loc) · 2.18 KB
/
XmlHelper.cs
File metadata and controls
74 lines (67 loc) · 2.18 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
using System;
using System.Xml;
using PluginCore.Managers;
namespace PluginCore.Helpers
{
public class XmlHelper
{
/// <summary>
/// Gets the value of the specified XmlNode.
/// </summary>
public static String GetValue(XmlNode node)
{
if (node != null && node.FirstChild != null) return node.FirstChild.Value;
else return null;
}
/// <summary>
/// Gets the specified attribute from the specified XmlNode.
/// </summary>
public static String GetAttribute(XmlNode node, String attName)
{
if (node != null && node.Attributes[attName] != null) return node.Attributes[attName].Value;
else return null;
}
/// <summary>
/// Checks that if the XmlNode has a value.
/// </summary>
public static Boolean HasValue(XmlNode node)
{
return (node != null && node.FirstChild != null && node.FirstChild.Value != null);
}
/// <summary>
/// Checks if the XmlNode has the specified attribute.
/// </summary>
public static Boolean HasAttribute(XmlNode node, String attName)
{
return (node != null && node.Attributes[attName] != null);
}
/// <summary>
/// Reads a xml file and returns it as a XmlNode. Returns null on failure.
/// </summary>
public static XmlNode LoadXmlDocument(String file)
{
try
{
XmlDocument document = new XmlDocument();
document.PreserveWhitespace = false;
document.Load(file);
try
{
XmlNode declNode = document.FirstChild;
XmlNode rootNode = declNode.NextSibling;
return rootNode;
}
catch (Exception ex1)
{
ErrorManager.ShowError(ex1);
return null;
}
}
catch (Exception ex2)
{
ErrorManager.ShowError(ex2);
return null;
}
}
}
}