Returns the inner text of the single node selected from the specified xpath if found; otherwise, null. : XPath « XML « C# / C Sharp






Returns the inner text of the single node selected from the specified xpath if found; otherwise, null.

       
using System;
using System.Xml;

namespace SnapDragon.ECommerce.Shipping
{
  /// <summary>
  /// Provides extensions methods for parsing xml.
  /// </summary>
  internal static class TrackingUtil
  {
    /// <summary>
    /// Returns the inner text of the single node selected from the specified xpath if found; otherwise, null.
    /// </summary>
    /// <param name="pNode"></param>
    /// <param name="pXpath"></param>
    /// <returns></returns>
    public static string SelectSingleNodeInnerTextOrNull(this XmlNode pNode, string pXpath)
    {
      XmlNode result = pNode.SelectSingleNode(pXpath);
      if (result == null)
      {
        return null;
      }

      return result.InnerText;
    }
    
  }
}

   
    
    
    
    
    
    
  








Related examples in the same category

1.XPathNavigator
2.XPathNodeIterator
3.Select by path
4.Find Elements with an XPath SearchFind Elements with an XPath Search
5.XPath Query Demo
6.Read XML node using the XML path
7.XmlQuery Example
8. XPath Expression Syntax
9.Using XPath to get string value, integer value and boolean value
10.Extensions.XPathSelectElement selects an XElement using a XPath expression
11.Extensions.XPathSelectElements Selects a collection of elements using an XPath expression.
12.Returns the string result from evaluating an xpath expression against the given document and context.
13.Gets the text value from the element located by the given XPath.
14.Get an array of nodes matching an XPath expression
15.Schema Reference Util