Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Read XML nodes into Data Dictionary
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using System.Xml; using System.Xml.Linq; namespace Rextester { public class Program { public static void Main(string[] args) { string data = "<data><test>foo</test><test>foobbbbb</test><bar>123</bar><username>foobar</username></data>"; XDocument doc = XDocument.Parse(data); Dictionary<string, string> dataDictionary = new Dictionary<string, string>(); foreach (XElement element in doc.Descendants().Where(p => p.HasElements == false)) { int keyInt = 0; string keyName = element.Name.LocalName; var parent = element.Parent; while(parent != null) { keyName = (parent.Name.LocalName + "." + keyName).Replace("data.",""); parent = parent.Parent; } while (dataDictionary.ContainsKey(keyName)) { keyName = keyName + "_" + keyInt++; } dataDictionary.Add(keyName, element.Value); } foreach(var x in dataDictionary) { Console.WriteLine("keyName: " + x.Key + " value: " + x.Value); } } } }
run
|
edit
|
history
|
help
0
SierpinskiTriangleChaosGameRecursion
Bases5
sdfrgthyjui65trfvf
Reverse words in string
const
Compression Decompressor
ok
yari
Random number + IF var change2
Test