Skip to content

Instantly share code, notes, and snippets.

@jamessdixon
Created November 8, 2018 23:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamessdixon/28414bb21226bcd1622f728bc12ec7b4 to your computer and use it in GitHub Desktop.
Save jamessdixon/28414bb21226bcd1622f728bc12ec7b4 to your computer and use it in GitHub Desktop.
#r "System.Xml.Linq.dll"
#r "Newtonsoft.Json"
open System.IO
open System.Xml
open System.Xml.Linq
open Newtonsoft.Json
let convert xmlPath jsonPath =
let xmlString = File.ReadAllText(xmlPath)
let xDocument = XDocument.Parse(xmlString)
let document = new XmlDocument()
document.LoadXml(xDocument.ToString())
let json = JsonConvert.SerializeXmlNode(document)
File.WriteAllText(jsonPath,json)
//let xmlPath = "//Users//jamesdixon//GitHub//ChickenSoftware.XamlParser//ChickenSoftware.XamlParser//XmlLookupData//Scenario_Unit.xml"
//let jsonPath = "//Users//jamesdixon//GitHub//ChickenSoftware.XamlParser//ChickenSoftware.XamlParser//JsonLookupData//Scenario_Unit.json"
//convert xmlPath jsonPath
let xmlFolder = "//Users//jamesdixon//GitHub//ChickenSoftware.XamlParser//ChickenSoftware.XamlParser//XmlLookupData"
let jsonFolder = "//Users//jamesdixon//GitHub//ChickenSoftware.XamlParser//ChickenSoftware.XamlParser//JsonLookupData"
let info = DirectoryInfo(xmlFolder)
info.GetFiles()
|> Array.filter(fun f -> f.Extension = ".xml")
|> Array.map(fun f -> f.FullName, jsonFolder + "//" + f.Name.Replace(".xml", ".json"))
|> Array.iter(fun (x,j) -> convert x j)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment