LoadXml
using System;
using System.Collections.Specialized;
using System.Xml;
namespace AI_Portal_Cloud.Infrastructure
{
public class LoadXML
{
/// <summary>
/// Loads the XML file.
/// </summary>
/// <param name="fileName">Name of the file.</param>
/// <returns></returns>
private static StringDictionary LoadXMLFile(string fileName)
{
StringDictionary dictionary = new StringDictionary();
XmlDocument xDoc = new XmlDocument();
XmlNode xRootNode;
XmlNode xNode;
String strID = "";
String strValue = "";
try
{
xDoc.Load(fileName);
xRootNode = xDoc.FirstChild.NextSibling;
foreach (XmlNode xNodeLoopVariable in xRootNode.ChildNodes)
{
xNode = xNodeLoopVariable;
if (xNode.NodeType == XmlNodeType.Element)
{
strID = xNode.Attributes["ID"].Value.ToString();
strValue = xNode.Attributes["VALUE"].Value.ToString();
dictionary.Add(strID, strValue);
strID = string.Empty;
strValue = string.Empty;
}
}
return dictionary;
}
finally
{
xDoc = null;
}
}
/// <summary>
/// Loads the files.
/// </summary>
/// <param name="fileName">Name of the file.</param>
/// <returns></returns>
public static StringDictionary LoadFiles(string fileName)
{
return LoadXMLFile(fileName);
}
}
}
Comments
Post a Comment