i have below xml
<?xml version="1.0" encoding="utf-8"?> <revisions> <revision name="r1"> <mastertags> <mastertag name="mt1"> <childtags> <childtag>ct1</childtag> </childtags> </mastertag> <mastertag name="mt2"> <childtags> <childtag>ct4</childtag> </childtags> </mastertag> </revision> <revision name="r2"> <mastertags> <mastertag name="mt6"> <childtags> <childtag>ct21</childtag> <childtag>ct22</childtag> <childtag>ct23</childtag> </childtags> </mastertag> <mastertag name="mt7"> <childtags> <childtag>ct24</childtag> <childtag>ct25</childtag> <childtag>ct26</childtag> </childtags> </mastertag> </revision> </revisions> i want convert xml dictionary of dictionaries using linq
dim dicrevisiontags new dictionary(of string, dictionary(of string, list(of string))) i tried using
dim document = xdocument.load("inputxml.xml") also
dim ccc = document.elements("revisions").todictionary(function(e) e.elements("revision").todictionary(function(d) d.elements("mastertags"))) but unable construct linq give output as
r1-> key, value( m1, list(of ct1)) , value( m2, list(of ct4)) r2-> key, value( m6, list(of ct21 ct22 ct23)) , value( m7, list(of ct24 ct25 ct26)) thanks gurpreet gill
you can use following:
var result = doc.root .elements("revision") .todictionary(x => (string)x.attribute("name"), x => x.element("mastertags") .elements("mastertag") .todictionary(y => (string)y.attribute("name"), y => y.element("childtags") .elements("childtag") .select(z => (string)z) .tolist())); it c#, should able translate it.
Comments
Post a Comment