c# - How to get the values of all the elements in an XML into an array? -
for example :
i have following xml,
<?xml version="1.0" encoding="utf-8"?> <test> <name>testrun</name> <syncbyte>ff</syncbyte> <som>53</som> <pdadd>7e</pdadd> <lenlsb>08</lenlsb> </test>
i values tags "syncbyte", "som", "padd" , "lenlsb" single array. there option within xml accomplish this?
p.s. there close 20+ tags in xml , not tags contain values time. hence if there single command values of xml, great.
with linq xml:
var xml = @"<?xml version=""1.0"" encoding=""utf-8""?> <test> <name>testrun</name> <syncbyte>ff</syncbyte> <som>53</som> <pdadd>7e</pdadd> <lenlsb>08</lenlsb> </test>"; var doc = xdocument.parse(xml); string[] values = doc.root.descendants().select(x => x.value).toarray();
Comments
Post a Comment