Node Exists by XPath - CSharp System.Xml

CSharp examples for System.Xml:XML Node

Description

Node Exists by XPath

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;//  w  w  w.  j a  v  a 2 s  .  c o m
using System;

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

Related Tutorials