c# - How to add an XML file and read key value pair into a dictionary? -
this question has answer here:
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
Post a Comment