Get Attribute value : Attribute « 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.Design Patterns
8.Development Class
9.Event
10.File Stream
11.Generics
12.GUI Windows Form
13.Language Basics
14.LINQ
15.Network
16.Office
17.Reflection
18.Regular Expressions
19.Security
20.Services Event
21.Thread
22.Web Services
23.Windows
24.Windows Presentation Foundation
25.XML
26.XML LINQ
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source
C# / C Sharp » XML » AttributeScreenshots 
Get Attribute value
 

//Microsoft Public License (Ms-PL)
//http://dbmlmanager.codeplex.com/license

#region using
using System;
using System.Xml;
#endregion

namespace DbmlManager.Lib.Utility
{
  #region Class Docs
  /// <summary>
  /// Summary description for XmlUtil.
  /// </summary>
  #endregion

  public class XmlUtil
  {

    #region GetAttrib(XmlNode node, string attrib, string defVal)
    public static string GetAttrib(XmlNode node, string attrib, string defVal)
    {
      XmlAttribute xmlAttrib = node.Attributes[attrib];
      if (xmlAttrib == null)
        return defVal;

      string val = xmlAttrib.Value;
      return (val == null? defVal : val;
    }
    #endregion
    #region GetAttribOrThrow(XmlNode node, string attrib)
    public static string GetAttribOrThrow(XmlNode node, string attrib)
    {
      string val = GetAttrib(node, attrib, null);
      if (val == null)
        throw new Exception(String.Format("Attribute '{0}' not specified in node '{1}'", attrib, node.Name));

      return val;
    }
    #endregion

  }
}

   
  
Related examples in the same category
1.Set Attribute Value
2.Get Attribute Value
3.Get Int value from xml attribute
4.Get attribute or return default value
5.Get Bool Attribute Or Throw exception
6.Get attribute value and convert to integer type
7.Get attribute value and convert to integer type or throw exception
8.Get Attribute and return Int64
9.Get Attribute and return Int64 or throw exception
10.Adds an XmlAttribute to a XmlNode
11.Get boolean value if an attribute is 1 or true
12.Attempts to get and cast attribute from an XmlElement
13.Attempts to get and convert an attribute from an XmlElement
14.Gets a string from an attribute or node.
15.Remove all the xml namespaces (xmlns) attributes in the xml string
16.Get Attribute With Conversion
17.Find a single Attribute of the type 'attributeType' from the supplied class
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.