264
|
1 using System;
|
|
2 using System.IO;
|
|
3 using System.Reflection;
|
|
4 using System.Xml;
|
|
5 using System.Xml.Xsl;
|
|
6 using Implab.Components;
|
|
7 using Implab.Formats.Json;
|
|
8
|
|
9 namespace Implab.Xml {
|
|
10 public class XmlToJson {
|
|
11 const string XmlToJsonTransformId = "Implab.Xml.json.xsl";
|
|
12
|
|
13 static LazyAndWeak<XslCompiledTransform> m_default = new LazyAndWeak<XslCompiledTransform>(CreateTransform, true);
|
|
14
|
|
15 public static XslCompiledTransform Default {
|
|
16 get { return m_default.Value; }
|
|
17 }
|
|
18
|
|
19 protected static XslCompiledTransform CreateTransform() {
|
|
20 var transform = new XslCompiledTransform();
|
|
21 using(var reader = XmlReader.Create(GetDefaultTransform())) {
|
|
22 transform.Load(reader);
|
|
23 }
|
|
24 return transform;
|
|
25 }
|
|
26
|
|
27 protected static Stream GetDefaultTransform() {
|
|
28 return Assembly.GetExecutingAssembly().GetManifestResourceStream(XmlToJsonTransformId);
|
|
29 }
|
|
30
|
|
31
|
|
32 }
|
|
33 } |