Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

XMlUtility.cs

Posted on 2009-02-15
3
Medium Priority
?
430 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

0
Comment
Question by:mathieu_cupryk
  • 2
3 Comments
 
LVL 15

Accepted Solution

by:
Praveen Venu earned 1500 total points
ID: 23651445
Can you please explain?
0
 

Author Comment

by:mathieu_cupryk
ID: 23651549
check AbleCommerce
0
 

Author Closing Comment

by:mathieu_cupryk
ID: 31547147
       version = versionInfo.DocumentElement != null ? versionInfo.DocumentElement.GetAttribute("Version") : "1.0.0";
                build = versionInfo.DocumentElement != null ? versionInfo.DocumentElement.GetAttribute("BuildNumber") : "unknown";
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Screencast - Getting to Know the Pipeline
Suggested Courses
Course of the Month15 days, 18 hours left to enroll

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question