annotate Implab/Xml/JsonXmlReader.cs @ 278:6691aff01de1 v3

Implab: added XmlDefaultSeializer (SerializersPool is now obsolete) Implab.ServiceHost: rewritten TypeReference (added support for nested types), stable API
author cin
date Thu, 03 May 2018 09:59:44 +0300
parents 74e048cbaac8
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
228
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents: 227
diff changeset
1 using Implab.Formats.Json;
227
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
2 using System;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
3 using System.Collections.Generic;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
4 using System.Globalization;
264
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents: 251
diff changeset
5 using System.IO;
227
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
6 using System.Linq;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
7 using System.Xml;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
8
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
9 namespace Implab.Xml {
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
10 public class JsonXmlReader : XmlReader {
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
11 struct JsonContext {
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
12 public string localName;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
13 public bool skip;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
14 }
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
15
229
5f7a3e1d32b9 JsonXmlReader performance tuning
cin
parents: 228
diff changeset
16 JsonReader m_parser;
227
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
17 JsonXmlReaderOptions m_options;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
18 JsonXmlReaderPosition m_position = JsonXmlReaderPosition.Initial;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
19 XmlNameTable m_nameTable;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
20
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
21 readonly string m_jsonRootName;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
22 readonly string m_jsonNamespace;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
23 readonly string m_jsonPrefix;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
24 readonly bool m_jsonFlattenArrays;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
25 readonly string m_jsonArrayItemName;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
26
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
27 string m_jsonLocalName;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
28 string m_jsonValueName;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
29 bool m_jsonSkip; // indicates wheather to generate closing tag for objects or arrays
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
30
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
31 readonly Stack<JsonContext> m_jsonNameStack = new Stack<JsonContext>();
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
32
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
33 XmlQualifiedName m_elementQName;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
34 string m_elementPrefix;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
35 int m_elementDepth;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
36 bool m_elementIsEmpty;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
37
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
38 XmlQualifiedName m_qName;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
39 string m_prefix;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
40 int m_xmlDepth;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
41
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
42 XmlSimpleAttribute[] m_attributes;
236
302ca905c19e JsonReader optimizations
cin
parents: 229
diff changeset
43 string m_value;
227
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
44 bool m_isEmpty;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
45
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
46 XmlNodeType m_nodeType = XmlNodeType.None;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
47
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
48 bool m_isAttribute; // indicates that we are reading attribute nodes
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
49 int m_currentAttribute;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
50 bool m_currentAttributeRead;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
51
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
52
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
53 XmlNameContext m_context;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
54
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
55 readonly string m_xmlnsPrefix;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
56 readonly string m_xmlnsNamespace;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
57 readonly string m_xsiPrefix;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
58 readonly string m_xsiNamespace;
265
74e048cbaac8 Restored lost JsonXmlCaseTransform from version 2.1
cin
parents: 264
diff changeset
59 readonly JsonXmlCaseTransform m_caseTransform;
227
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
60
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
61
229
5f7a3e1d32b9 JsonXmlReader performance tuning
cin
parents: 228
diff changeset
62 public JsonXmlReader(JsonReader parser, JsonXmlReaderOptions options) {
227
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
63 Safe.ArgumentNotNull(parser, nameof(parser));
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
64 m_parser = parser;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
65
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
66 m_options = options ?? new JsonXmlReaderOptions();
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
67
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
68 m_jsonFlattenArrays = m_options.FlattenArrays;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
69 m_nameTable = m_options.NameTable ?? new NameTable();
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
70
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
71 m_jsonRootName = m_nameTable.Add(string.IsNullOrEmpty(m_options.RootName) ? "data" : m_options.RootName);
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
72 m_jsonArrayItemName = m_nameTable.Add(string.IsNullOrEmpty(m_options.ArrayItemName) ? "item" : m_options.ArrayItemName);
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
73 m_jsonNamespace = m_nameTable.Add(m_options.NamespaceUri ?? string.Empty);
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
74 m_jsonPrefix = m_nameTable.Add(m_options.NodesPrefix ?? string.Empty);
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
75 m_xmlnsPrefix = m_nameTable.Add(XmlNameContext.XmlnsPrefix);
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
76 m_xmlnsNamespace = m_nameTable.Add(XmlNameContext.XmlnsNamespace);
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
77 m_xsiPrefix = m_nameTable.Add(XmlNameContext.XsiPrefix);
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
78 m_xsiNamespace = m_nameTable.Add(XmlNameContext.XsiNamespace);
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
79
265
74e048cbaac8 Restored lost JsonXmlCaseTransform from version 2.1
cin
parents: 264
diff changeset
80 m_caseTransform = m_options.CaseTransform;
74e048cbaac8 Restored lost JsonXmlCaseTransform from version 2.1
cin
parents: 264
diff changeset
81
227
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
82 // TODO validate m_jsonRootName, m_jsonArrayItemName
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
83
229
5f7a3e1d32b9 JsonXmlReader performance tuning
cin
parents: 228
diff changeset
84 m_context = new XmlNameContext(null, 0);
227
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
85 }
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
86
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
87 public override int AttributeCount {
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
88 get {
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
89 return m_attributes == null ? 0 : m_attributes.Length;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
90 }
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
91 }
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
92
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
93 public override string BaseURI {
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
94 get {
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
95 return string.Empty;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
96 }
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
97 }
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
98
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
99 public override int Depth {
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
100 get {
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
101 return m_xmlDepth;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
102 }
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
103 }
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
104
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
105 public override bool EOF {
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
106 get {
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
107 return m_position == JsonXmlReaderPosition.Eof;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
108 }
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
109 }
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
110
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
111 public override bool IsEmptyElement {
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
112 get { return m_isEmpty; }
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
113 }
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
114
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
115
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
116 public override string LocalName {
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
117 get {
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
118 return m_qName.Name;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
119 }
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
120 }
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
121
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
122 public override string NamespaceURI {
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
123 get {
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
124 return m_qName.Namespace;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
125 }
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
126 }
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
127
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
128 public override XmlNameTable NameTable {
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
129 get {
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
130 return m_nameTable;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
131 }
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
132 }
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
133
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
134 public override XmlNodeType NodeType {
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
135 get {
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
136 return m_nodeType;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
137 }
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
138 }
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
139
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
140 public override string Prefix {
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
141 get {
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
142 return m_prefix;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
143 }
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
144 }
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
145
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
146 public override ReadState ReadState {
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
147 get {
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
148 switch (m_position) {
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
149 case JsonXmlReaderPosition.Initial:
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
150 return ReadState.Initial;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
151 case JsonXmlReaderPosition.Eof:
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
152 return ReadState.EndOfFile;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
153 case JsonXmlReaderPosition.Closed:
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
154 return ReadState.Closed;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
155 case JsonXmlReaderPosition.Error:
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
156 return ReadState.Error;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
157 default:
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
158 return ReadState.Interactive;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
159 };
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
160 }
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
161 }
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
162
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
163 public override string Value {
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
164 get {
236
302ca905c19e JsonReader optimizations
cin
parents: 229
diff changeset
165 return m_value;
227
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
166 }
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
167 }
265
74e048cbaac8 Restored lost JsonXmlCaseTransform from version 2.1
cin
parents: 264
diff changeset
168
227
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
169 public override string GetAttribute(int i) {
251
7c7e9ad6fe4a Prerelease version of RunnableComponent
cin
parents: 236
diff changeset
170 Safe.ArgumentInRange(i >= 0 && i < AttributeCount, nameof(i));
236
302ca905c19e JsonReader optimizations
cin
parents: 229
diff changeset
171 return m_attributes[i].Value;
227
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
172 }
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
173
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
174 public override string GetAttribute(string name) {
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
175 if (m_attributes == null)
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
176 return null;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
177 var qName = m_context.Resolve(name);
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
178 var attr = Array.Find(m_attributes, x => x.QName == qName);
236
302ca905c19e JsonReader optimizations
cin
parents: 229
diff changeset
179 var value = attr?.Value;
227
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
180 return value == string.Empty ? null : value;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
181 }
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
182
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
183 public override string GetAttribute(string name, string namespaceURI) {
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
184 if (m_attributes == null)
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
185 return null;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
186 var qName = new XmlQualifiedName(name, namespaceURI);
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
187 var attr = Array.Find(m_attributes, x => x.QName == qName);
236
302ca905c19e JsonReader optimizations
cin
parents: 229
diff changeset
188 var value = attr?.Value;
227
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
189 return value == string.Empty ? null : value;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
190 }
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
191
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
192 public override string LookupNamespace(string prefix) {
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
193 return m_context.ResolvePrefix(prefix);
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
194 }
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
195
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
196 public override bool MoveToAttribute(string name) {
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
197 if (m_attributes == null || m_attributes.Length == 0)
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
198 return false;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
199
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
200 var qName = m_context.Resolve(name);
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
201 var index = Array.FindIndex(m_attributes, x => x.QName == qName);
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
202 if (index >= 0) {
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
203 MoveToAttributeImpl(index);
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
204 return true;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
205 }
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
206 return false;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
207 }
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
208
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
209 public override bool MoveToAttribute(string name, string ns) {
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
210 if (m_attributes == null || m_attributes.Length == 0)
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
211 return false;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
212
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
213 var qName = m_context.Resolve(name);
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
214 var index = Array.FindIndex(m_attributes, x => x.QName == qName);
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
215 if (index >= 0) {
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
216 MoveToAttributeImpl(index);
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
217 return true;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
218 }
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
219 return false;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
220 }
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
221
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
222 void MoveToAttributeImpl(int i) {
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
223 if (!m_isAttribute) {
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
224 m_elementQName = m_qName;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
225 m_elementDepth = m_xmlDepth;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
226 m_elementPrefix = m_prefix;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
227 m_elementIsEmpty = m_isEmpty;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
228 m_isAttribute = true;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
229 }
265
74e048cbaac8 Restored lost JsonXmlCaseTransform from version 2.1
cin
parents: 264
diff changeset
230
227
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
231 var attr = m_attributes[i];
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
232
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
233
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
234 m_currentAttribute = i;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
235 m_currentAttributeRead = false;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
236 m_nodeType = XmlNodeType.Attribute;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
237
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
238 m_xmlDepth = m_elementDepth + 1;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
239 m_qName = attr.QName;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
240 m_value = attr.Value;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
241 m_prefix = attr.Prefix;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
242 }
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
243
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
244 public override bool MoveToElement() {
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
245 if (m_isAttribute) {
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
246 m_value = null;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
247 m_nodeType = XmlNodeType.Element;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
248 m_xmlDepth = m_elementDepth;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
249 m_prefix = m_elementPrefix;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
250 m_qName = m_elementQName;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
251 m_isEmpty = m_elementIsEmpty;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
252 m_isAttribute = false;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
253 return true;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
254 }
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
255 return false;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
256 }
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
257
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
258 public override bool MoveToFirstAttribute() {
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
259 if (m_attributes != null && m_attributes.Length > 0) {
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
260 MoveToAttributeImpl(0);
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
261 return true;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
262 }
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
263 return false;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
264 }
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
265
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
266 public override bool MoveToNextAttribute() {
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
267 if (m_isAttribute) {
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
268 var next = m_currentAttribute + 1;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
269 if (next < AttributeCount) {
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
270 MoveToAttributeImpl(next);
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
271 return true;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
272 }
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
273 return false;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
274 } else {
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
275 return MoveToFirstAttribute();
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
276 }
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
277
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
278 }
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
279
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
280 public override bool ReadAttributeValue() {
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
281 if (!m_isAttribute || m_currentAttributeRead)
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
282 return false;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
283
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
284 ValueNode(m_attributes[m_currentAttribute].Value);
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
285 m_currentAttributeRead = true;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
286 return true;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
287 }
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
288
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
289 public override void ResolveEntity() {
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
290 /* do nothing */
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
291 }
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
292
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
293 /// <summary>
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
294 /// Determines do we need to increase depth after the current node
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
295 /// </summary>
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
296 /// <returns></returns>
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
297 public bool IsSibling() {
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
298 switch (m_nodeType) {
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
299 case XmlNodeType.None: // start document
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
300 case XmlNodeType.Attribute: // after attribute only it's content can be iterated with ReadAttributeValue method
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
301 return false;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
302 case XmlNodeType.Element:
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
303 // if the elemnt is empty the next element will be it's sibling
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
304 return m_isEmpty;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
305 default:
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
306 return true;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
307 }
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
308 }
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
309
236
302ca905c19e JsonReader optimizations
cin
parents: 229
diff changeset
310 void ValueNode(string value) {
227
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
311 if (!IsSibling()) // the node is nested
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
312 m_xmlDepth++;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
313
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
314 m_qName = XmlQualifiedName.Empty;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
315 m_nodeType = XmlNodeType.Text;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
316 m_prefix = string.Empty;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
317 m_value = value;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
318 m_isEmpty = false;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
319 m_attributes = null;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
320 }
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
321
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
322 void ElementNode(string name, string ns, XmlSimpleAttribute[] attrs, bool empty) {
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
323 if (!IsSibling()) // the node is nested
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
324 m_xmlDepth++;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
325
229
5f7a3e1d32b9 JsonXmlReader performance tuning
cin
parents: 228
diff changeset
326 var context = m_context;
227
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
327 List<XmlSimpleAttribute> definedAttrs = null;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
328
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
329 // define new namespaces
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
330 if (attrs != null) {
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
331 foreach (var attr in attrs) {
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
332 if (attr.QName.Name == "xmlns") {
229
5f7a3e1d32b9 JsonXmlReader performance tuning
cin
parents: 228
diff changeset
333 if (context == m_context)
265
74e048cbaac8 Restored lost JsonXmlCaseTransform from version 2.1
cin
parents: 264
diff changeset
334 context = new XmlNameContext(m_context, m_xmlDepth);
236
302ca905c19e JsonReader optimizations
cin
parents: 229
diff changeset
335 context.DefinePrefix(attr.Value, string.Empty);
227
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
336 } else if (attr.Prefix == m_xmlnsPrefix) {
229
5f7a3e1d32b9 JsonXmlReader performance tuning
cin
parents: 228
diff changeset
337 if (context == m_context)
5f7a3e1d32b9 JsonXmlReader performance tuning
cin
parents: 228
diff changeset
338 context = new XmlNameContext(m_context, m_xmlDepth);
236
302ca905c19e JsonReader optimizations
cin
parents: 229
diff changeset
339 context.DefinePrefix(attr.Value, attr.QName.Name);
227
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
340 } else {
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
341 string attrPrefix;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
342 if (string.IsNullOrEmpty(attr.QName.Namespace))
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
343 continue;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
344
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
345 // auto-define prefixes
229
5f7a3e1d32b9 JsonXmlReader performance tuning
cin
parents: 228
diff changeset
346 if (!context.LookupNamespacePrefix(attr.QName.Namespace, out attrPrefix) || string.IsNullOrEmpty(attrPrefix)) {
227
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
347 // new namespace prefix added
229
5f7a3e1d32b9 JsonXmlReader performance tuning
cin
parents: 228
diff changeset
348 attrPrefix = context.CreateNamespacePrefix(attr.QName.Namespace);
227
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
349 attr.Prefix = attrPrefix;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
350
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
351 if (definedAttrs == null)
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
352 definedAttrs = new List<XmlSimpleAttribute>();
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
353
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
354 definedAttrs.Add(new XmlSimpleAttribute(attrPrefix, m_xmlnsNamespace, m_xmlnsPrefix, attr.QName.Namespace));
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
355 }
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
356 }
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
357 }
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
358 }
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
359
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
360 string p;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
361 // auto-define prefixes
229
5f7a3e1d32b9 JsonXmlReader performance tuning
cin
parents: 228
diff changeset
362 if (!context.LookupNamespacePrefix(ns, out p)) {
5f7a3e1d32b9 JsonXmlReader performance tuning
cin
parents: 228
diff changeset
363 if (context == m_context)
5f7a3e1d32b9 JsonXmlReader performance tuning
cin
parents: 228
diff changeset
364 context = new XmlNameContext(m_context, m_xmlDepth);
5f7a3e1d32b9 JsonXmlReader performance tuning
cin
parents: 228
diff changeset
365 p = context.CreateNamespacePrefix(ns);
227
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
366 if (definedAttrs == null)
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
367 definedAttrs = new List<XmlSimpleAttribute>();
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
368
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
369 definedAttrs.Add(new XmlSimpleAttribute(p, m_xmlnsNamespace, m_xmlnsPrefix, ns));
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
370 }
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
371
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
372 if (definedAttrs != null) {
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
373 if (attrs != null)
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
374 definedAttrs.AddRange(attrs);
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
375 attrs = definedAttrs.ToArray();
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
376 }
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
377
229
5f7a3e1d32b9 JsonXmlReader performance tuning
cin
parents: 228
diff changeset
378 if (!empty)
5f7a3e1d32b9 JsonXmlReader performance tuning
cin
parents: 228
diff changeset
379 m_context = context;
5f7a3e1d32b9 JsonXmlReader performance tuning
cin
parents: 228
diff changeset
380
227
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
381 m_nodeType = XmlNodeType.Element;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
382 m_qName = new XmlQualifiedName(name, ns);
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
383 m_prefix = p;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
384 m_value = null;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
385 m_isEmpty = empty;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
386 m_attributes = attrs;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
387 }
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
388
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
389 void EndElementNode(string name, string ns) {
229
5f7a3e1d32b9 JsonXmlReader performance tuning
cin
parents: 228
diff changeset
390 if (IsSibling()) {
5f7a3e1d32b9 JsonXmlReader performance tuning
cin
parents: 228
diff changeset
391 // closing the element which has children
227
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
392 m_xmlDepth--;
229
5f7a3e1d32b9 JsonXmlReader performance tuning
cin
parents: 228
diff changeset
393 }
227
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
394
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
395 string p;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
396 if (!m_context.LookupNamespacePrefix(ns, out p))
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
397 throw new Exception($"Failed to lookup namespace '{ns}'");
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
398
229
5f7a3e1d32b9 JsonXmlReader performance tuning
cin
parents: 228
diff changeset
399 if (m_context.Depth == m_xmlDepth)
5f7a3e1d32b9 JsonXmlReader performance tuning
cin
parents: 228
diff changeset
400 m_context = m_context.ParentContext;
5f7a3e1d32b9 JsonXmlReader performance tuning
cin
parents: 228
diff changeset
401
227
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
402 m_nodeType = XmlNodeType.EndElement;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
403 m_prefix = p;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
404 m_qName = new XmlQualifiedName(name, ns);
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
405 m_value = null;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
406 m_attributes = null;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
407 m_isEmpty = false;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
408 }
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
409
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
410 void XmlDeclaration() {
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
411 if (!IsSibling()) // the node is nested
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
412 m_xmlDepth++;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
413 m_nodeType = XmlNodeType.XmlDeclaration;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
414 m_qName = new XmlQualifiedName("xml");
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
415 m_value = "version='1.0'";
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
416 m_prefix = string.Empty;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
417 m_attributes = null;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
418 m_isEmpty = false;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
419 }
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
420
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
421 public override bool Read() {
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
422 try {
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
423 string elementName;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
424 XmlSimpleAttribute[] elementAttrs = null;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
425 MoveToElement();
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
426
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
427 switch (m_position) {
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
428 case JsonXmlReaderPosition.Initial:
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
429 m_jsonLocalName = m_jsonRootName;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
430 m_jsonSkip = false;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
431 XmlDeclaration();
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
432 m_position = JsonXmlReaderPosition.Declaration;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
433 return true;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
434 case JsonXmlReaderPosition.Declaration:
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
435 elementAttrs = new[] {
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
436 new XmlSimpleAttribute(m_xsiPrefix, m_xmlnsNamespace, m_xmlnsPrefix, m_xsiNamespace),
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
437 string.IsNullOrEmpty(m_jsonPrefix) ?
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
438 new XmlSimpleAttribute(m_xmlnsPrefix, string.Empty, string.Empty, m_jsonNamespace) :
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
439 new XmlSimpleAttribute(m_jsonPrefix, m_xmlnsNamespace, m_xmlnsPrefix, m_jsonNamespace)
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
440 };
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
441 break;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
442 case JsonXmlReaderPosition.ValueElement:
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
443 if (!m_isEmpty) {
229
5f7a3e1d32b9 JsonXmlReader performance tuning
cin
parents: 228
diff changeset
444 if (m_parser.ElementValue != null && !m_parser.ElementValue.Equals(string.Empty))
5f7a3e1d32b9 JsonXmlReader performance tuning
cin
parents: 228
diff changeset
445 ValueNode(m_parser.ElementValue);
5f7a3e1d32b9 JsonXmlReader performance tuning
cin
parents: 228
diff changeset
446 else
5f7a3e1d32b9 JsonXmlReader performance tuning
cin
parents: 228
diff changeset
447 goto case JsonXmlReaderPosition.ValueContent;
227
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
448 m_position = JsonXmlReaderPosition.ValueContent;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
449 return true;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
450 } else {
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
451 m_position = JsonXmlReaderPosition.ValueEndElement;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
452 break;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
453 }
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
454 case JsonXmlReaderPosition.ValueContent:
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
455 EndElementNode(m_jsonValueName, m_jsonNamespace);
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
456 m_position = JsonXmlReaderPosition.ValueEndElement;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
457 return true;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
458 case JsonXmlReaderPosition.Eof:
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
459 case JsonXmlReaderPosition.Closed:
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
460 case JsonXmlReaderPosition.Error:
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
461 return false;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
462 }
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
463
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
464 while (m_parser.Read()) {
265
74e048cbaac8 Restored lost JsonXmlCaseTransform from version 2.1
cin
parents: 264
diff changeset
465 var jsonName = m_nameTable.Add(TransformJsonName(m_parser.ElementName));
227
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
466
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
467 switch (m_parser.ElementType) {
228
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents: 227
diff changeset
468 case JsonElementType.BeginObject:
227
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
469 if (!EnterJsonObject(jsonName, out elementName))
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
470 continue;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
471
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
472 m_position = JsonXmlReaderPosition.BeginObject;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
473 ElementNode(elementName, m_jsonNamespace, elementAttrs, false);
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
474 break;
228
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents: 227
diff changeset
475 case JsonElementType.EndObject:
227
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
476 if (!LeaveJsonScope(out elementName))
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
477 continue;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
478
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
479 m_position = JsonXmlReaderPosition.EndObject;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
480 EndElementNode(elementName, m_jsonNamespace);
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
481 break;
228
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents: 227
diff changeset
482 case JsonElementType.BeginArray:
227
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
483 if (!EnterJsonArray(jsonName, out elementName))
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
484 continue;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
485
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
486 m_position = JsonXmlReaderPosition.BeginArray;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
487 ElementNode(elementName, m_jsonNamespace, elementAttrs, false);
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
488 break;
228
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents: 227
diff changeset
489 case JsonElementType.EndArray:
227
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
490 if (!LeaveJsonScope(out elementName))
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
491 continue;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
492
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
493 m_position = JsonXmlReaderPosition.EndArray;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
494 EndElementNode(elementName, m_jsonNamespace);
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
495 break;
228
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents: 227
diff changeset
496 case JsonElementType.Value:
227
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
497 if (!VisitJsonValue(jsonName, out m_jsonValueName))
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
498 continue;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
499
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
500 m_position = JsonXmlReaderPosition.ValueElement;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
501 if (m_parser.ElementValue == null)
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
502 // generate empty element with xsi:nil="true" attribute
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
503 ElementNode(
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
504 m_jsonValueName,
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
505 m_jsonNamespace,
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
506 new[] {
236
302ca905c19e JsonReader optimizations
cin
parents: 229
diff changeset
507 new XmlSimpleAttribute("nil", m_xsiNamespace, m_xsiPrefix, "true")
227
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
508 },
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
509 true
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
510 );
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
511 else
229
5f7a3e1d32b9 JsonXmlReader performance tuning
cin
parents: 228
diff changeset
512 ElementNode(m_jsonValueName, m_jsonNamespace, elementAttrs, m_parser.ElementValue.Equals(string.Empty));
227
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
513 break;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
514 default:
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
515 throw new Exception($"Unexpected JSON element {m_parser.ElementType}: {m_parser.ElementName}");
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
516 }
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
517 return true;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
518 }
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
519
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
520 m_position = JsonXmlReaderPosition.Eof;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
521 return false;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
522 } catch {
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
523 m_position = JsonXmlReaderPosition.Error;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
524 throw;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
525 }
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
526 }
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
527
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
528 void SaveJsonName() {
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
529 m_jsonNameStack.Push(new JsonContext {
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
530 skip = m_jsonSkip,
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
531 localName = m_jsonLocalName
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
532 });
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
533
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
534 }
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
535
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
536 bool EnterJsonObject(string name, out string elementName) {
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
537 SaveJsonName();
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
538 m_jsonSkip = false;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
539
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
540 if (string.IsNullOrEmpty(name)) {
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
541 if (m_jsonNameStack.Count != 1 && !m_jsonFlattenArrays)
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
542 m_jsonLocalName = m_jsonArrayItemName;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
543 } else {
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
544 m_jsonLocalName = name;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
545 }
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
546
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
547 elementName = m_jsonLocalName;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
548 return true;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
549 }
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
550
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
551 /// <summary>
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
552 /// Called when JSON parser visits BeginArray ('[') element.
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
553 /// </summary>
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
554 /// <param name="name">Optional property name if the array is the member of an object</param>
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
555 /// <returns>true if element should be emited, false otherwise</returns>
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
556 bool EnterJsonArray(string name, out string elementName) {
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
557 SaveJsonName();
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
558
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
559 if (string.IsNullOrEmpty(name)) {
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
560 // m_jsonNameStack.Count == 1 means the root node
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
561 if (m_jsonNameStack.Count != 1 && !m_jsonFlattenArrays)
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
562 m_jsonLocalName = m_jsonArrayItemName;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
563
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
564 m_jsonSkip = false; // we should not flatten arrays inside arrays or in the document root
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
565 } else {
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
566 m_jsonLocalName = name;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
567 m_jsonSkip = m_jsonFlattenArrays;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
568 }
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
569 elementName = m_jsonLocalName;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
570
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
571 return !m_jsonSkip;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
572 }
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
573
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
574 bool VisitJsonValue(string name, out string elementName) {
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
575 if (string.IsNullOrEmpty(name)) {
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
576 // m_jsonNameStack.Count == 0 means that JSON document consists from simple value
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
577 elementName = (m_jsonNameStack.Count == 0 || m_jsonFlattenArrays) ? m_jsonLocalName : m_jsonArrayItemName;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
578 } else {
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
579 elementName = name;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
580 }
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
581 return true;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
582 }
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
583
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
584 bool LeaveJsonScope(out string elementName) {
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
585 elementName = m_jsonLocalName;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
586 var skip = m_jsonSkip;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
587
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
588 var prev = m_jsonNameStack.Pop();
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
589 m_jsonLocalName = prev.localName;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
590 m_jsonSkip = prev.skip;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
591
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
592 return !skip;
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
593 }
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
594
265
74e048cbaac8 Restored lost JsonXmlCaseTransform from version 2.1
cin
parents: 264
diff changeset
595 private string TransformJsonName(string name) {
74e048cbaac8 Restored lost JsonXmlCaseTransform from version 2.1
cin
parents: 264
diff changeset
596 if (m_caseTransform == JsonXmlCaseTransform.None || string.IsNullOrEmpty(name)) {
74e048cbaac8 Restored lost JsonXmlCaseTransform from version 2.1
cin
parents: 264
diff changeset
597 return name;
74e048cbaac8 Restored lost JsonXmlCaseTransform from version 2.1
cin
parents: 264
diff changeset
598 } else if (m_caseTransform == JsonXmlCaseTransform.UcFirst) {
74e048cbaac8 Restored lost JsonXmlCaseTransform from version 2.1
cin
parents: 264
diff changeset
599 return JsonXmlReader.UppercaseFirst(name);
74e048cbaac8 Restored lost JsonXmlCaseTransform from version 2.1
cin
parents: 264
diff changeset
600 } else {
74e048cbaac8 Restored lost JsonXmlCaseTransform from version 2.1
cin
parents: 264
diff changeset
601 return JsonXmlReader.LowercaseFirst(name);
74e048cbaac8 Restored lost JsonXmlCaseTransform from version 2.1
cin
parents: 264
diff changeset
602 }
74e048cbaac8 Restored lost JsonXmlCaseTransform from version 2.1
cin
parents: 264
diff changeset
603 }
74e048cbaac8 Restored lost JsonXmlCaseTransform from version 2.1
cin
parents: 264
diff changeset
604
264
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents: 251
diff changeset
605 protected override void Dispose(bool disposing) {
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents: 251
diff changeset
606 if (disposing)
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents: 251
diff changeset
607 Safe.Dispose(m_parser);
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents: 251
diff changeset
608 base.Dispose(true);
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents: 251
diff changeset
609 }
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents: 251
diff changeset
610
227
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
611 public override string ToString() {
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
612 switch (NodeType) {
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
613 case XmlNodeType.Element:
236
302ca905c19e JsonReader optimizations
cin
parents: 229
diff changeset
614 return $"<{Name} {string.Join(" ", (m_attributes ?? new XmlSimpleAttribute[0]).Select(x => $"{x.Prefix}{(string.IsNullOrEmpty(x.Prefix) ? "" : ":")}{x.QName.Name}='{x.Value}'"))} {(IsEmptyElement ? "/" : "")}>";
227
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
615 case XmlNodeType.Attribute:
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
616 return $"@{Name}";
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
617 case XmlNodeType.Text:
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
618 return $"{Value}";
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
619 case XmlNodeType.CDATA:
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
620 return $"<![CDATA[{Value}]]>";
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
621 case XmlNodeType.EntityReference:
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
622 return $"&{Name};";
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
623 case XmlNodeType.EndElement:
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
624 return $"</{Name}>";
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
625 default:
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
626 return $".{NodeType} {Name} {Value}";
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
627 }
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
628 }
264
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents: 251
diff changeset
629
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents: 251
diff changeset
630 #region static methods
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents: 251
diff changeset
631
265
74e048cbaac8 Restored lost JsonXmlCaseTransform from version 2.1
cin
parents: 264
diff changeset
632 //
74e048cbaac8 Restored lost JsonXmlCaseTransform from version 2.1
cin
parents: 264
diff changeset
633 // Static Methods
74e048cbaac8 Restored lost JsonXmlCaseTransform from version 2.1
cin
parents: 264
diff changeset
634 //
74e048cbaac8 Restored lost JsonXmlCaseTransform from version 2.1
cin
parents: 264
diff changeset
635 private static string LowercaseFirst(string s) {
74e048cbaac8 Restored lost JsonXmlCaseTransform from version 2.1
cin
parents: 264
diff changeset
636 char[] array = s.ToCharArray();
74e048cbaac8 Restored lost JsonXmlCaseTransform from version 2.1
cin
parents: 264
diff changeset
637 array[0] = char.ToLower(array[0]);
74e048cbaac8 Restored lost JsonXmlCaseTransform from version 2.1
cin
parents: 264
diff changeset
638 return new string(array);
74e048cbaac8 Restored lost JsonXmlCaseTransform from version 2.1
cin
parents: 264
diff changeset
639 }
74e048cbaac8 Restored lost JsonXmlCaseTransform from version 2.1
cin
parents: 264
diff changeset
640
74e048cbaac8 Restored lost JsonXmlCaseTransform from version 2.1
cin
parents: 264
diff changeset
641 private static string UppercaseFirst(string s) {
74e048cbaac8 Restored lost JsonXmlCaseTransform from version 2.1
cin
parents: 264
diff changeset
642 char[] array = s.ToCharArray();
74e048cbaac8 Restored lost JsonXmlCaseTransform from version 2.1
cin
parents: 264
diff changeset
643 array[0] = char.ToUpper(array[0]);
74e048cbaac8 Restored lost JsonXmlCaseTransform from version 2.1
cin
parents: 264
diff changeset
644 return new string(array);
74e048cbaac8 Restored lost JsonXmlCaseTransform from version 2.1
cin
parents: 264
diff changeset
645 }
74e048cbaac8 Restored lost JsonXmlCaseTransform from version 2.1
cin
parents: 264
diff changeset
646
264
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents: 251
diff changeset
647 public static JsonXmlReader CreateJsonXmlReader(TextReader textReader, JsonXmlReaderOptions options = null) {
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents: 251
diff changeset
648 var jsonReader = JsonReader.Create(textReader);
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents: 251
diff changeset
649 return new JsonXmlReader(jsonReader, options);
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents: 251
diff changeset
650 }
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents: 251
diff changeset
651
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents: 251
diff changeset
652 public static JsonXmlReader CreateJsonXmlReader(Stream stream, JsonXmlReaderOptions options = null) {
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents: 251
diff changeset
653 var jsonReader = JsonReader.Create(stream);
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents: 251
diff changeset
654 return new JsonXmlReader(jsonReader, options);
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents: 251
diff changeset
655 }
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents: 251
diff changeset
656
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents: 251
diff changeset
657 public static JsonXmlReader CreateJsonXmlReader(string file, JsonXmlReaderOptions options = null) {
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents: 251
diff changeset
658 var jsonReader = JsonReader.Create(file);
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents: 251
diff changeset
659 return new JsonXmlReader(jsonReader, options);
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents: 251
diff changeset
660 }
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents: 251
diff changeset
661
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents: 251
diff changeset
662 #endregion
227
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
663 }
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents:
diff changeset
664 }