c# - How to add an XML file and read key value pair into a dictionary? -


i new programming. trying add xml file in order store mappings. want ready these key value pairs in dictionary. following format of xml thinking:

<?xml version="1.0" encoding="utf-8" ?> <map>   <add keyword="keyword1" replacewith="replaceme1"/>   <add keyword="keyword2" replacewith="replaceme2"/>   </map> 

can please tell me if format correct? if is, how read c# dictionary?

you can use linq xml:

var xdoc = xdocument.load(path_to_xml); var map = xdoc.root.elements()                    .todictionary(a => (string)a.attribute("keyword"),                                  => (string)a.attribute("replacewith")); 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -