/// <summary> /// Per ogni valore riscontrato tramite l'xPath costruisce un dizionario con l'xpath specifico come chiave e il valore dell'xpath valutato come valore /// Es: {"//books/book[1]/authors/author[1]", "Antonio"},{"//books/book[1]/authors/author[2]", "Erasmo"},{"//books/book[1]/authors/author[3]", "Renata"}, ecc... /// </summary> /// <typeparam name="TType">Tipo di valore da salvare nel dizionario come valore</typeparam> /// <param name="nav">Navigator da valutare</param> /// <param name="xPath">Espressione XPath Generica Es. //books/book/authors/author</param> /// <returns>Dizionario xPath esplicito, valore</returns> public static IDictionary <string, TType> GetValuesFromXPathDictionary <TType>(this XPathNavigator nav, string xPath) { IDictionary <string, TType> dictionary = new Dictionary <string, TType>(); XPathExpression expr = nav.Compile(xPath); XPathNodeIterator iterator = nav.Select(expr); while (iterator.MoveNext()) { XPathNavigator currentNavigator = iterator.Current.Clone(); var currentXPath = currentNavigator.GetFullXPath(); var currentValue = String.IsNullOrEmpty(currentNavigator.InnerXml) ? currentNavigator.OuterXml : nav.InnerXml; dictionary.Add(currentXPath, currentValue.GetValue <TType>()); } return(dictionary); }