Get Value String from Xml : DOM « XML « C# / C Sharp

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Date Time
8.Design Patterns
9.Development Class
10.Event
11.File Stream
12.Generics
13.GUI Windows Form
14.Internationalization I18N
15.Language Basics
16.LINQ
17.Network
18.Office
19.Reflection
20.Regular Expressions
21.Security
22.Services Event
23.Thread
24.Web Services
25.Windows
26.Windows Presentation Foundation
27.XML
28.XML LINQ
C# / C Sharp » XML » DOMScreenshots 
Get Value String from Xml
  

#region Copyright (c2000-2010 Developer Express Inc.
/*
{*******************************************************************}
{                                                                   }
{       Developer Express .NET Component Library                    }
{                                                                   }
{                                                                   }
{       Copyright (c) 2000-2010 Developer Express Inc.              }
{       ALL RIGHTS RESERVED                                         }
{                                                                   }
{   The entire contents of this file is protected by U.S. and       }
{   International Copyright Laws. Unauthorized reproduction,        }
{   reverse-engineering, and distribution of all or any portion of  }
{   the code contained in this file is strictly prohibited and may  }
{   result in severe civil and criminal penalties and will be       }
{   prosecuted to the maximum extent possible under the law.        }
{                                                                   }
{   RESTRICTIONS                                                    }
{                                                                   }
{   THIS SOURCE CODE AND ALL RESULTING INTERMEDIATE FILES           }
{   ARE CONFIDENTIAL AND PROPRIETARY TRADE                          }
{   SECRETS OF DEVELOPER EXPRESS INC. THE REGISTERED DEVELOPER IS   }
{   LICENSED TO DISTRIBUTE THE PRODUCT AND ALL ACCOMPANYING .NET    }
{   CONTROLS AS PART OF AN EXECUTABLE PROGRAM ONLY.                 }
{                                                                   }
{   THE SOURCE CODE CONTAINED WITHIN THIS FILE AND ALL RELATED      }
{   FILES OR ANY PORTION OF ITS CONTENTS SHALL AT NO TIME BE        }
{   COPIED, TRANSFERRED, SOLD, DISTRIBUTED, OR OTHERWISE MADE       }
{   AVAILABLE TO OTHER INDIVIDUALS WITHOUT EXPRESS WRITTEN CONSENT  }
{   AND PERMISSION FROM DEVELOPER EXPRESS INC.                      }
{                                                                   }
{   CONSULT THE END USER LICENSE AGREEMENT FOR INFORMATION ON       }
{   ADDITIONAL RESTRICTIONS.                                        }
{                                                                   }
{*******************************************************************}
*/
#endregion Copyright (c2000-2010 Developer Express Inc.

namespace DevExpress.Xpo.Data.Services {
    using System;
    using System.Diagnostics;
    using System.Xml;
    
    public static class XmlUtils {
        public static string GetValueString(object value) {
            Debug.Assert(value != null, "value != null");
            string result = null;
            Type valueType = value.GetType();
            valueType = Nullable.GetUnderlyingType(valueType?? valueType;
            if (typeof(String== valueType) {
                result = string.Format("'{0}'"((string)value).Replace("'""''"));
            else if (typeof(Boolean== valueType) {
                result = XmlConvert.ToString((bool)value);
            else if (typeof(Byte== valueType) {
                result = XmlConvert.ToString((byte)value);
            else if (typeof(DateTime== valueType) {
                result = XmlConvert.ToString((DateTime)value, XmlDateTimeSerializationMode.RoundtripKind);
            else if (typeof(Decimal== valueType) {
                result = XmlConvert.ToString((decimal)value);
            else if (typeof(Double== valueType) {
                result = XmlConvert.ToString((double)value);
            else if (typeof(Guid== valueType) {
                result = value.ToString();
            else if (typeof(Int16== valueType) {
                result = XmlConvert.ToString((Int16)value);
            else if (typeof(Int32== valueType) {
                result = XmlConvert.ToString((Int32)value);
            else if (typeof(Int64== valueType) {
                result = XmlConvert.ToString((Int64)value);
            else if (typeof(SByte== valueType) {
                result = XmlConvert.ToString((SByte)value);
            else if (typeof(Single== valueType) {
                result = XmlConvert.ToString((Single)value);
            else if (typeof(byte[]) == valueType) {
                byte[] byteArray = (byte[])value;
                result = Convert.ToBase64String(byteArray);
            else if (typeof(System.Data.Linq.Binary== valueType) {
                return GetValueString(((System.Data.Linq.Binary)value).ToArray());
            else if (typeof(System.Xml.Linq.XElement== valueType) {
                result = ((System.Xml.Linq.XElement)value).ToString(System.Xml.Linq.SaveOptions.None);
            else {
                result = null;
            }
            Debug.Assert(result != null, "result != null");
            return result;
        }
    }
}

   
    
  
Related examples in the same category
1.DOM feature check
2.Create Xml Document, Node
3.Load String from xml element
4.Load boolean value from xml element
5.Get integer value from xml element
6.Get attribute from XmlNode
7.Set Xml Node Value
8.Get InnerXml without changing the spacing
9.Get Inner Xml
10.Add Xml Element
11.Returns the InnerText value from a node or string.Empty if the node is null.
12.Sets the inner text in a node. If the node doesn't exist, it creates a new one and adds the text to it.
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.