annotate Implab/Xml/XmlToJson.cs @ 274:22629bf26121 v3

Unity xml configuration, alpha2
author cin
date Fri, 27 Apr 2018 04:47:52 +0300
parents 3a6e18c432be
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
264
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents:
diff changeset
1 using System;
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents:
diff changeset
2 using System.IO;
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents:
diff changeset
3 using System.Reflection;
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents:
diff changeset
4 using System.Xml;
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents:
diff changeset
5 using System.Xml.Xsl;
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents:
diff changeset
6 using Implab.Components;
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents:
diff changeset
7 using Implab.Formats.Json;
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents:
diff changeset
8
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents:
diff changeset
9 namespace Implab.Xml {
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents:
diff changeset
10 public class XmlToJson {
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents:
diff changeset
11 const string XmlToJsonTransformId = "Implab.Xml.json.xsl";
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents:
diff changeset
12
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents:
diff changeset
13 static LazyAndWeak<XslCompiledTransform> m_default = new LazyAndWeak<XslCompiledTransform>(CreateTransform, true);
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents:
diff changeset
14
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents:
diff changeset
15 public static XslCompiledTransform Default {
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents:
diff changeset
16 get { return m_default.Value; }
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents:
diff changeset
17 }
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents:
diff changeset
18
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents:
diff changeset
19 protected static XslCompiledTransform CreateTransform() {
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents:
diff changeset
20 var transform = new XslCompiledTransform();
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents:
diff changeset
21 using(var reader = XmlReader.Create(GetDefaultTransform())) {
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents:
diff changeset
22 transform.Load(reader);
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents:
diff changeset
23 }
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents:
diff changeset
24 return transform;
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents:
diff changeset
25 }
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents:
diff changeset
26
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents:
diff changeset
27 protected static Stream GetDefaultTransform() {
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents:
diff changeset
28 return Assembly.GetExecutingAssembly().GetManifestResourceStream(XmlToJsonTransformId);
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents:
diff changeset
29 }
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents:
diff changeset
30
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents:
diff changeset
31
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents:
diff changeset
32 }
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents:
diff changeset
33 }