Get an array of nodes matching an XPath expression : XPath « XML « C# / C Sharp






Get an array of nodes matching an XPath expression

       
// Copyright ? Microsoft Corporation.
// This source file is subject to the Microsoft Permissive License.
// See http://www.microsoft.com/resources/sharedsource/licensingbasics/sharedsourcelicenses.mspx.
// All other rights reserved.

using System;
using System.Text;
using System.Xml;
using System.Xml.Xsl;
using System.Xml.XPath;
using System.Diagnostics;
using System.Collections.Generic;

class Util {

    public static class BuildComponentUtilities {

        // get an array of nodes matching an XPath expression

        public static XPathNavigator[] ConvertNodeIteratorToArray (XPathNodeIterator iterator) {
            XPathNavigator[] result = new XPathNavigator[iterator.Count];
            for (int i = 0; i < result.Length; i++) {
                iterator.MoveNext();
                result[i] = iterator.Current.Clone();
                // clone is required or all entries will equal Current!
            }
            return(result);
        }

    }

}

   
    
    
    
    
    
    
  








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.Returns the inner text of the single node selected from the specified xpath if found; otherwise, null.
15.Schema Reference Util