1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| public static Dictionary<string,string> XML2Dct()
{
string fName = @"C:\tst.xml";
Dictionary<string, string> dct = new Dictionary<string, string>();
using (StreamReader sr = new StreamReader(fName))
{
XPathDocument doc = new XPathDocument(sr);
XPathNavigator nav = doc.CreateNavigator();
XPathNodeIterator iter = nav.Select("/tests/*");
while (iter.MoveNext())
{
string key = iter.Current.Value.Trim();
iter.MoveNext();
string value = iter.Current.Value.Trim();
dct.Add(key, value);
}
}
return dct;
} |
Partager