LoadXmlFilesUtility
/*-----------------------------------------------------------------
File Name : LoadXML.cs
Created By : Navin Kumar
Created on : Sep-2017
Revision History:
------------------------------------------------------------------*/
using System;
using System.Collections.Specialized;
using System.Xml;
namespace InsiderTrading.Infrastructure.Common
{/// <summary>
/// used to load xml file
/// </summary>
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