XMlUtility.cs

How do I build an XmlUtility.xml
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Web;
using System.Web.Caching;
using System.Xml;
using System.IO.Compression;

/// <summary>
/// Singleton class that holds data regarding the version of omegalove
/// </summary>
public class OmegaLoveVersion
{
    private static object syncLock = new object();
    private string _Version;
    private string _Build;
    public string Version { get { return _Version; } }
    public string Build { get { return _Build; } }
    private OmegaLoveVersion(string version, string build)
    {
        _Version = version;
        _Build = build;
    }
    public static OmegaLoveVersion Instance
    {
        get
        {
            HttpContext context = HttpContext.Current;
            OmegaLoveVersion tempInstance = context.Cache["OmegaLoveVersion"] as OmegaLoveVersion;
            if (tempInstance != null)
                return tempInstance;
           
            //MUST INITIALIZE NEW INSTANCE
            string version, build;
            string versionFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
                "App_Data/VersionInfo.xml");
           
            try
            {
                XmlDocument versionInfo = new XmlDocument();
                versionInfo.Load(versionFile);
                version = XmlUtility.GetElementValue(versionInfo.DocumentElement, "Version");
                build = XmlUtility.GetElementValue(versionInfo.DocumentElement, "BuildNumber");
            }
            catch
            {
                version = "1.0.0";
                build = "unknown";
            }
            tempInstance = new OmegaLoveVersion(version, build);
            CacheDependency fileDep = new CacheDependency(versionFile);
            lock (syncLock)
            {
                context.Cache.Remove("OmegaLoveVersion");
                context.Cache.Add("OmegaLoveVersion", tempInstance, fileDep, Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration, CacheItemPriority.NotRemovable, null);
            }
            return tempInstance;
        }
    }

}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Xml;
using System.IO;
using System.Text;
using System.Collections.Specialized;
 
public static class XmlUtility
{
    public static XmlElement CreateElement(XmlNode xmlDoc, string sXPath);
    public static object Deserialize(string Xml, Type ThisType);
    public static string EscapeXmlChars(string In);
    public static string GetAttributeValue(XmlElement xmlElem, string sAttribute, string sDefault);
    public static string GetAttributeValue(XmlNode xmlDoc, string sAttribute, string sDefault);
    public static XmlElement GetElement(XmlNode xmlDoc, string sXPath, bool bCreate);
    public static string GetElementValue(string Xml, string Element);
    public static string GetElementValue(XmlElement element, string xPath);
    public static string GetElementValue(XmlElement element, string xPath, string defaultValue);
    public static string GetElementValue(XmlElement element, string xPath, XmlNamespaceManager nsmgr);
    public static string GetElementValue(XmlNode element, string xPath, string defaultValue);
    public static string GetElementValue(XmlElement element, string xPath, XmlNamespaceManager nsmgr, string defaultValue);
    public static string GetTopElement(string Xml);
    public static string Iso88591BytesToString(byte[] InBytes);
    public static string Iso88591StreamToString(Stream stream);
    public static byte[] Serialize(object ObjectToSerialize);
    public static byte[] Serialize(object ObjectToSerialize, Encoding encoding);
    public static void SetAttributeValue(XmlElement xmlElem, string sAttribute, string sValue);
    public static void SetAttributeValue(XmlNode xmlDoc, string sAttribute, string sValue);
    public static void SetElementValue(XmlNode xmlDoc, string sXPath, string sValue);
    public static void SetElementValue(XmlNode xmlDoc, string sXPath, string sValue, bool bCreate);
    public static void SetElementValue(XmlNode xmlDoc, string sXPath, string sValue, bool bCreate, bool bCreateIfEmpty);
    public static byte[] StringToIso88591Bytes(string InString);
    public static byte[] StringToUtf8Bytes(string InString);
    public static string Utf8BytesToString(byte[] InBytes);
    public static string Utf8StreamToString(Stream Utf8Stream);
    public static StringDictionary XML2Dic(string sXMLDoc);
    public static StringDictionary XML2Dic(XmlNode objNode);
}

Open in new window

mathieu_cuprykAsked:
Who is Participating?
 
Praveen VenuTechnical Project ManagerCommented:
Can you please explain?
0
 
mathieu_cuprykAuthor Commented:
check AbleCommerce
0
 
mathieu_cuprykAuthor Commented:
       version = versionInfo.DocumentElement != null ? versionInfo.DocumentElement.GetAttribute("Version") : "1.0.0";
                build = versionInfo.DocumentElement != null ? versionInfo.DocumentElement.GetAttribute("BuildNumber") : "unknown";
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.