Example of XML conversion to DYNAMIC and its use.
Example of XML conversion to DYNAMIC and its use.
To start, we will need some libraries:
using System;
using System.ComponentModel;
using System.Xml.Linq;
using Newtonsoft.Json;
Code:
string str = "<response><setter><name>Kiril</name></setter></response>";
XDocument doc = XDocument.Parse(str);
string jsn = JsonConvert.SerializeXNode(doc);
dynamic res = JsonConvert.DeserializeObject(jsn);
Console.WriteLine(res.response.setter.name);
This code converts a string to XML, then XML to JSON and then to a dynamic object.
Then, from the object, it gets the Name property and outputs it to the console.
Comments (0)
No comments yet.