We help IT Professionals succeed at work.

XMlUtility.cs

mathieu_cupryk
on
Medium Priority
448 Views
Last Modified: 2012-05-06
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

Comment
Watch Question

Technical Project Manager
Commented:
Can you please explain?

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
check AbleCommerce

Author

Commented:
       version = versionInfo.DocumentElement != null ? versionInfo.DocumentElement.GetAttribute("Version") : "1.0.0";
                build = versionInfo.DocumentElement != null ? versionInfo.DocumentElement.GetAttribute("BuildNumber") : "unknown";
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.