Mega Code Archive

 
Categories / C# / XML
 

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);         }     } }