Wednesday, May 11, 2022

Working with XML in C# Deserializing Dynamic Objects

                 XDocument doc = XDocument.Parse(xml);

                string jsonText = JsonConvert.SerializeXNode(doc);
                dynamic dyn = JsonConvert.DeserializeObject<ExpandoObject>(jsonText);                string qticomment = dyn.root.qticomment;
                string duration = dyn.root.duration;You just look at the structure of the XML and dot down the properties to get the values.If you come to an array:                List<dynamic> qtimetadata = dyn.root.itemmetadata.qtimetadata.qtimetadatafield;
                foreach (dynamic metadata in qtimetadata)
                {
                    if (metadata.fieldlabel == "ILIAS_VERSION")
                    {
                        ILIAS_VERSION = metadata.fieldentry;
                    }

No comments:

Check This Out!

More Links to Good Information