|
/*
* Xml Messages Class
* ==============================================================
* Creator Ch.V.L.Mahendra
* Created 17-Sep-2006
* Environments IIS 5.*, IIS 6.0, .Net Framework 2.0
* Description
*
* Provides an interface to the XML Messages file.
*
* Change Log
* ==============================================================
* Version Date Author Changes
* 0.1 17-Sep-2006 Ch.V.L.Mahendra Created
*/
using System;
using System.Xml;
using System.Data;
using System.Text;
using System.Collections;
namespace ContextSensitiveHelp.Pages.Xml
{
/// <summary>
/// Class to manage the xml messages from the xml file.
/// </summary>
public class XmlMessage
{
#region Private Variables
/// <summary>
/// Variable to hold the path of the Xml file
/// </summary>
private static string strXmlFilePath;
/// <summary>
/// Variable to hold the Xml Document
/// </summary>
private static XmlDocument objDocument;
#endregion
#region Public Methods
/// <summary>
/// Returns the requested message from the xml file.
/// </summary>
/// <param name="strReference">The reference number for the message</param>
/// <returns>A message entry structure holding the message information</returns>
public static MessageEntry GetMessageEntry(string strReference)
{
XmlNode objTitle;
XmlNode objMessage;
XmlNodeList objNodeList;
objNodeList = XmlMessage.GetNodes("/messages/entry[@ref='" + strReference + "']/title");
if (objNodeList.Count == 0) return new MessageEntry(strReference, "There has been an error in the application. No supporting information is available for this error.", "Unknown Error");
objTitle = objNodeList[0];
objNodeList = XmlMessage.GetNodes("/messages/entry[@ref='" + strReference + "']/message");
if (objNodeList.Count == 0) return new MessageEntry(strReference, "There has been an error in the application. No supporting information is available for this error.", "Unknown Error");
objMessage = objNodeList[0];
return new MessageEntry(strReference, objMessage.InnerText, objTitle.InnerText);
}
/// <summary>
/// Returns messages relating to the context
/// </summary>
/// <param name="strContext">The context to get messages for</param>
/// <returns>An xml node list of structures</returns>
public static XmlNodeList GetContextHelp(string strContext)
{
XmlNodeList objNodeList = XmlMessage.GetNodes("/messages/entry[@context='" + strContext + "']");
return objNodeList;
}
/// <summary>
/// Fetch a node list for the requested XPath query.
/// </summary>
/// <param name="strXPath">Specifies the criteria for the nodes to return</param>
/// <returns>A node list of the elements it contains</returns>
public static XmlNodeList GetNodes(string strXPath)
{
XmlElement objRoot = objDocument.DocumentElement;
return objRoot.SelectNodes(strXPath);
}
#endregion
#region Properties
/// <summary>
/// The absolute file path of the Xml file being read.
/// </summary>
public static string XmlFile
{
get
{
return strXmlFilePath;
}
set
{
strXmlFilePath = value;
}
}
/// <summary>
/// Returns the Xml document object of the Xml settings file.
/// </summary>
public static XmlDocument Xml
{
get
{
return objDocument;
}
set
{
objDocument = value;
}
}
#endregion
}
#region Struct
/// <summary>
/// Structure to hold the content of an xml message.
/// </summary>
public struct MessageEntry
{
/// <summary>
/// The reference for the message
/// </summary>
public string Reference;
/// <summary>
/// The content for the message
/// </summary>
public string Message;
/// <summary>
/// The title for the message
/// </summary>
public string Title;
/// <summary>
/// Constructor for the message.
/// </summary>
/// <param name="strReference">Reference value for this message</param>
/// <param name="strMessage">Content of the message</param>
/// <param name="strTitle">Title of the message</param>
public MessageEntry(string strReference, string strMessage, string strTitle)
{
this.Reference = strReference;
this.Message = strMessage;
this.Title = strTitle;
}
}
#endregion
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.