mathieu_cupryk
asked on
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["OmegaLoveVe rsion"] as OmegaLoveVersion;
if (tempInstance != null)
return tempInstance;
//MUST INITIALIZE NEW INSTANCE
string version, build;
string versionFile = Path.Combine(AppDomain.Cur rentDomain .BaseDirec tory,
"App_Data/VersionInfo.xml" );
try
{
XmlDocument versionInfo = new XmlDocument();
versionInfo.Load(versionFi le);
version = XmlUtility.GetElementValue (versionIn fo.Documen tElement, "Version");
build = XmlUtility.GetElementValue (versionIn fo.Documen tElement, "BuildNumber");
}
catch
{
version = "1.0.0";
build = "unknown";
}
tempInstance = new OmegaLoveVersion(version, build);
CacheDependency fileDep = new CacheDependency(versionFil e);
lock (syncLock)
{
context.Cache.Remove("Omeg aLoveVersi on");
context.Cache.Add("OmegaLo veVersion" , tempInstance, fileDep, Cache.NoAbsoluteExpiration , Cache.NoSlidingExpiration, CacheItemPriority.NotRemov able, null);
}
return tempInstance;
}
}
}
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["OmegaLoveVe
if (tempInstance != null)
return tempInstance;
//MUST INITIALIZE NEW INSTANCE
string version, build;
string versionFile = Path.Combine(AppDomain.Cur
"App_Data/VersionInfo.xml"
try
{
XmlDocument versionInfo = new XmlDocument();
versionInfo.Load(versionFi
version = XmlUtility.GetElementValue
build = XmlUtility.GetElementValue
}
catch
{
version = "1.0.0";
build = "unknown";
}
tempInstance = new OmegaLoveVersion(version, build);
CacheDependency fileDep = new CacheDependency(versionFil
lock (syncLock)
{
context.Cache.Remove("Omeg
context.Cache.Add("OmegaLo
}
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);
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
version = versionInfo.DocumentElemen t != null ? versionInfo.DocumentElemen t.GetAttri bute("Vers ion") : "1.0.0";
build = versionInfo.DocumentElemen t != null ? versionInfo.DocumentElemen t.GetAttri bute("Buil dNumber") : "unknown";
build = versionInfo.DocumentElemen
ASKER