How can I extract key value pairs from this xml example using linq:
<foo> <add key="key1" Value="val1"/> <add key="key2" Value="val2"/> <add key="key3" Value="val3"/> <foo/>
Try the following:
string text = "<foo>...</foo>"; var pairs = XDocument.Parse(text) .Descendants("add") .Select(x => new { Key = x.Attribute("key").Value, Value = x.Attribute("Value").Value }) .ToList();
XDocument fooXML = new XDocument.Load("foo.xml") var query = from a in fooXML.Element("foo").Elements("add") select new { key = a.Attribute("key").Value, val = a.Attribute("Value").Value }; // Then do what you want with the query...
Source: https://habr.com/ru/post/1722594/More articles:ColdFusion, CFDirectory и французский - coldfusionЕсть ли способ разработать новые JSR для устройств с поддержкой Java ME? - mobileАльтернативы API TPM/TSS Linux API - securityHow to disable WebSite action on Wix if no web features are selected? - iisJ2ME development and native API - java-mehttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1722595/net-windows-forms-datagridview-have-to-click-combobox-column-three-times-to-get-focus&usg=ALkJrhihQu-LxenKrV7FXQ6HRTAu-j8yEQSQLite and J2ME - javahttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1722597/passing-parameters-to-a-user-control&usg=ALkJrhjanIF9XHO7LTVwAcNwPi6bt_PeLAFree UML library for .NET. - c #Safe ERB language? - securityAll Articles