diff Implab/Xml/XmlToJson.cs @ 264:3a6e18c432be v3

Added XmlToJson xsl transformation. Added JsonXmlReader.CreateJsonXmlReader(...) methods Added SerializationHelpers.SerializeJson/DeserializeJson methods
author cin
date Mon, 16 Apr 2018 18:43:49 +0300
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Implab/Xml/XmlToJson.cs	Mon Apr 16 18:43:49 2018 +0300
@@ -0,0 +1,33 @@
+using System;
+using System.IO;
+using System.Reflection;
+using System.Xml;
+using System.Xml.Xsl;
+using Implab.Components;
+using Implab.Formats.Json;
+
+namespace Implab.Xml {
+    public class XmlToJson {
+        const string XmlToJsonTransformId = "Implab.Xml.json.xsl";
+
+        static LazyAndWeak<XslCompiledTransform> m_default = new LazyAndWeak<XslCompiledTransform>(CreateTransform, true);
+
+        public static XslCompiledTransform Default {
+            get { return m_default.Value; }
+        }
+
+        protected static XslCompiledTransform CreateTransform() {
+            var transform = new XslCompiledTransform();
+            using(var reader = XmlReader.Create(GetDefaultTransform())) {
+                transform.Load(reader);
+            }
+            return transform;
+        }
+
+        protected static Stream GetDefaultTransform() {
+            return Assembly.GetExecutingAssembly().GetManifestResourceStream(XmlToJsonTransformId);
+        }
+
+
+    }
+}
\ No newline at end of file