Search This Blog

Monday 25 November 2019

Convert XML To Json with NULL Value Handling, Remove Empty Element from XML Node

Convert XML To Json with NULL Value Handling

XDocument doc = XDocument.Parse("Specify the XML Content in String Format");
 
doc.Descendants().Where(f => f.IsEmpty || string.IsNullOrWhiteSpace(f.Value)).Remove();
 
string jsonText = JsonConvert.SerializeXNode(doc); // this will convert XNode to Json Text
Namespaces used
using System.Xml.Linq;
using Newtonsoft.Json;
using System.Linq; 

No comments:

Post a Comment

Popular Posts