-4

How to add keypair values into the dictionary directly from the xml file. On uploading the keypair values of an xml file should be added to the dictionary... And from that I should read those keypair values

Madhina
  • 1
  • 3
  • http://stackoverflow.com/questions/18261921/how-to-add-an-xml-file-and-read-key-value-pair-into-a-dictionary might help – MusicLovingIndianGirl Oct 07 '15 at 05:17
  • While jhmt's answer is probably sufficient, it would be very helpful to see an example of your XML structure so we can provide you with more appropriate answers, rather than relying on guesswork. – Eraph Oct 07 '15 at 05:48

1 Answers1

3

If your xml file's scheme is like this,

<?xml version="1.0" encoding="utf-8" ?>
<Root>
  <Key1>Val1</Key1>
  <Key2>Val2</Key2>
  <Key3>Val3</Key3>
</Root>

I think this would be work well.

var xdoc = XDocument.Load(pathToXmlFile);
var dictionary = xdoc.Root.Elements().ToDictionary(k => k.Name, v => v.Value);
jhmt
  • 1,401
  • 1
  • 11
  • 15