Get String from XmlNode - CSharp System.Xml

CSharp examples for System.Xml:XML Node

Description

Get String from XmlNode

Demo Code


using System.Globalization;
using System.Security.Cryptography;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Collections;
using System.Xml.XPath;
using System.Text;
using System.Xml;
using System.IO;//from w w w .j  av  a2  s. com
using System;

public class Main{
        /// <summary>
      /// 
      /// </summary>
      /// <param name="Node"></param>
      /// <param name="NodeName"></param>
      /// <returns></returns>
      public static string GetString(XmlNode Node, string NodeName)
      {
         XmlNode fnode = Node.SelectSingleNode(NodeName);
         if ( fnode != null )
            return fnode.InnerText;
         else
            return "";
      }
        /// <summary>
      /// 
      /// </summary>
      /// <param name="Navigator"></param>
      /// <param name="XPath"></param>
      /// <returns></returns>
      public static string GetString(XPathNavigator Navigator, XPathExpression XPath)
      {
         XPathNodeIterator i = Navigator.Select(XPath);
         if (i.MoveNext())
         {
            return i.Current.Value;
         }
         else
         {
            return "";
         }
      }
        /// <summary>
      /// 
      /// </summary>
      /// <param name="Navigator"></param>
      /// <param name="NodeName"></param>
      /// <returns></returns>
      public static string GetString(XPathNavigator Navigator, string NodeName)
      {
         XPathNodeIterator i = Navigator.Select(NodeName);
         if (i.MoveNext())
         {
            return i.Current.Value;
         }
         else
         {
            return "";
         }
      }
}

Related Tutorials