讀取XML我有這樣一個XML文件:錯誤而在字典
<APICollection><API name="myapiName" message="myAPIMessage" /></APICollection>
當我試圖在這樣的詞典閱讀本:
Dictionary<string,string> apiMap = new Dictionary<string,string>();
XDocument xdoc = XDocument.Load(path);
apiMap = xdoc.Root.Elements()
.ToDictionary(a => (string)a.Attribute("apiName"), a => (string)a.Attribute("apiMessage"));
一切都很正常。但是,如果我有相同的密鑰(名稱)的多個條目,我得到一個通用的例外是這樣的:
An item with the same key has already been added.
我不知道我能做些什麼來修改錯誤消息至少給了哪個鍵存在多個倍。任何人都可以幫忙嗎?
感謝,
Harit