Created
February 15, 2013 18:12
-
-
Save sdurandeu/4962217 to your computer and use it in GitHub Desktop.
Json to XML using Newtonsoft.Json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace JsonToXml | |
{ | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Xml; | |
using Newtonsoft; | |
using System.IO; | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
// load json | |
string[] files = Directory.GetFiles(Directory.GetCurrentDirectory(), "*.txt"); | |
foreach (string file in files) | |
{ | |
using (StreamReader streamReader = new StreamReader(file)) | |
{ | |
// convert it | |
XmlDocument doc = (XmlDocument)Newtonsoft.Json.JsonConvert.DeserializeXmlNode(streamReader.ReadToEnd(), "Operations"); | |
// save it | |
XmlTextWriter writer = new XmlTextWriter(file.Replace(".txt",".xml"), null); | |
writer.Formatting = Formatting.Indented; | |
doc.Save(writer); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment