annotate Implab/JSON/JSONXmlReader.cs @ 59:21611344d366

code cleanup
author cin
date Wed, 18 Jun 2014 03:54:02 +0400
parents 1710dcda34bb
children 10c7337d29e7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
58
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
1 using Implab;
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
2 using Implab.JSON;
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
3 using Implab.Parsing;
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
4 using System;
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
5 using System.Collections.Generic;
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
6 using System.Linq;
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
7 using System.Text;
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
8 using System.Threading.Tasks;
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
9 using System.Xml;
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
10
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
11 namespace ConsPlay {
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
12 public class JSONXmlReader : XmlReader {
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
13
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
14 enum ValueContext {
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
15 Undefined,
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
16 ElementStart,
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
17 ElementValue,
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
18 ElementEnd,
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
19 ElementEmpty
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
20 }
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
21
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
22 struct LocalNameContext {
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
23 public string localName;
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
24 public bool isArray;
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
25 }
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
26
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
27 JSONParser m_parser;
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
28 ValueContext m_valueContext;
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
29 ReadState m_state = ReadState.Initial;
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
30 Stack<LocalNameContext> m_localNameStack = new Stack<LocalNameContext>();
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
31 LocalNameContext m_localName;
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
32 string m_rootName = "json";
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
33 string m_prefix = String.Empty;
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
34 string m_namespaceUri = String.Empty;
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
35 bool m_flattenArrays = false;
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
36 NameTable m_nameTable = new NameTable();
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
37 int m_depthCorrection = 0;
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
38
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
39 public JSONXmlReader(JSONParser parser) {
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
40 Safe.ArgumentNotNull(parser, "parser");
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
41 m_parser = parser;
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
42 }
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
43
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
44 /// <summary>
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
45 /// Always 0, JSON doesn't support attributes
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
46 /// </summary>
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
47 public override int AttributeCount {
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
48 get { return 0; }
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
49 }
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
50
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
51 public override string BaseURI {
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
52 get { return String.Empty; }
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
53 }
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
54
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
55 public override int Depth {
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
56 get {
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
57 return m_localNameStack.Count+m_depthCorrection;
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
58 }
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
59 }
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
60
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
61 public override bool EOF {
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
62 get { return m_parser.EOF; }
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
63 }
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
64
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
65 /// <summary>
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
66 /// Always throws an exception
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
67 /// </summary>
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
68 /// <param name="i"></param>
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
69 /// <returns></returns>
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
70 public override string GetAttribute(int i) {
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
71 throw new ArgumentOutOfRangeException();
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
72 }
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
73
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
74 /// <summary>
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
75 /// Always returns empty string
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
76 /// </summary>
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
77 /// <param name="name"></param>
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
78 /// <param name="namespaceURI"></param>
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
79 /// <returns></returns>
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
80 public override string GetAttribute(string name, string namespaceURI) {
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
81 return String.Empty;
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
82 }
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
83
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
84 /// <summary>
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
85 /// Always returns empty string
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
86 /// </summary>
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
87 /// <param name="name"></param>
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
88 /// <returns></returns>
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
89 public override string GetAttribute(string name) {
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
90 return String.Empty;
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
91 }
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
92
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
93 public override bool IsEmptyElement {
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
94 get { return m_parser.ElementType == JSONElementType.Value && m_valueContext == ValueContext.ElementEmpty; }
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
95 }
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
96
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
97 public override string LocalName {
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
98 get { return m_localName.localName; }
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
99 }
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
100
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
101 public override string LookupNamespace(string prefix) {
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
102 if (String.IsNullOrEmpty(prefix) || prefix == m_prefix)
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
103 return m_namespaceUri;
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
104 else
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
105 return String.Empty;
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
106 }
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
107
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
108 public override bool MoveToAttribute(string name, string ns) {
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
109 return false;
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
110 }
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
111
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
112 public override bool MoveToAttribute(string name) {
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
113 return false;
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
114 }
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
115
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
116 public override bool MoveToElement() {
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
117 return false;
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
118 }
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
119
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
120 public override bool MoveToFirstAttribute() {
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
121 return false;
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
122 }
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
123
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
124 public override bool MoveToNextAttribute() {
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
125 return false;
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
126 }
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
127
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
128 public override XmlNameTable NameTable {
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
129 get { return m_nameTable; }
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
130 }
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
131
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
132 public override string NamespaceURI {
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
133 get { return m_namespaceUri; }
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
134 }
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
135
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
136 public override XmlNodeType NodeType {
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
137 get {
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
138 switch (m_parser.ElementType) {
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
139 case JSONElementType.BeginObject:
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
140 case JSONElementType.BeginArray:
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
141 return XmlNodeType.Element;
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
142 case JSONElementType.EndObject:
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
143 case JSONElementType.EndArray:
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
144 return XmlNodeType.EndElement;
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
145 case JSONElementType.Value:
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
146 switch (m_valueContext) {
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
147 case ValueContext.ElementStart:
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
148 case ValueContext.ElementEmpty:
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
149 return XmlNodeType.Element;
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
150 case ValueContext.ElementValue:
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
151 return XmlNodeType.Text;
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
152 case ValueContext.ElementEnd:
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
153 return XmlNodeType.EndElement;
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
154 default:
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
155 throw new InvalidOperationException();
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
156 }
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
157 default:
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
158 throw new InvalidOperationException();
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
159 }
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
160 }
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
161 }
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
162
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
163 public override string Prefix {
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
164 get { return m_prefix; }
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
165 }
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
166
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
167 public override bool Read() {
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
168 if (m_state != System.Xml.ReadState.Interactive && m_state != System.Xml.ReadState.Initial)
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
169 return false;
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
170
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
171 if (m_state == ReadState.Initial)
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
172 m_state = System.Xml.ReadState.Interactive;
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
173
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
174 try {
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
175 switch (m_parser.ElementType) {
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
176 case JSONElementType.Value:
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
177 switch (m_valueContext) {
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
178 case ValueContext.ElementStart:
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
179 SetLocalName(String.Empty);
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
180 m_valueContext = ValueContext.ElementValue;
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
181 return true;
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
182 case ValueContext.ElementValue:
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
183 RestoreLocalName();
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
184 m_valueContext = ValueContext.ElementEnd;
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
185 return true;
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
186 case ValueContext.ElementEmpty:
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
187 case ValueContext.ElementEnd:
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
188 RestoreLocalName();
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
189 break;
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
190 }
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
191 break;
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
192 case JSONElementType.EndArray:
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
193 case JSONElementType.EndObject:
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
194 RestoreLocalName();
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
195 break;
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
196 }
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
197 string itemName = m_parser.ElementType == JSONElementType.None ? m_rootName : m_flattenArrays ? m_localName.localName : "item";
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
198 while (m_parser.Read()) {
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
199 if (!String.IsNullOrEmpty(m_parser.ElementName))
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
200 itemName = m_parser.ElementName;
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
201
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
202 switch (m_parser.ElementType) {
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
203 case JSONElementType.BeginArray:
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
204 if (m_flattenArrays && !m_localName.isArray) {
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
205 m_depthCorrection--;
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
206 SetLocalName(itemName, true);
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
207 continue;
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
208 } else {
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
209 SetLocalName(itemName, true);
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
210 }
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
211 break;
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
212 case JSONElementType.BeginObject:
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
213 SetLocalName(itemName);
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
214 break;
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
215 case JSONElementType.EndArray:
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
216 if (m_flattenArrays && !m_localNameStack.Peek().isArray) {
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
217 RestoreLocalName();
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
218 m_depthCorrection++;
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
219 continue;
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
220 }
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
221 break;
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
222 case JSONElementType.EndObject:
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
223 break;
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
224 case JSONElementType.Value:
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
225 SetLocalName(itemName);
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
226 m_valueContext = m_parser.ElementValue == null ? ValueContext.ElementEmpty : ValueContext.ElementStart;
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
227 break;
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
228 default:
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
229 break;
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
230 }
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
231 return true;
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
232 }
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
233
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
234 m_state = System.Xml.ReadState.EndOfFile;
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
235 return false;
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
236 } catch {
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
237 m_state = System.Xml.ReadState.Error;
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
238 throw;
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
239 }
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
240 }
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
241
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
242 public override bool ReadAttributeValue() {
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
243 return false;
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
244 }
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
245
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
246 public override ReadState ReadState {
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
247 get { return m_state; }
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
248 }
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
249
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
250 public override void ResolveEntity() {
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
251 // do nothing
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
252 }
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
253
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
254 public override string Value {
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
255 get { return m_parser.ElementValue == null ? String.Empty : m_parser.ElementValue.ToString(); }
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
256 }
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
257
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
258 void SetLocalName(string name) {
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
259 m_localNameStack.Push(m_localName);
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
260 m_localName.localName = name;
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
261 m_localName.isArray = false;
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
262 }
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
263
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
264 void SetLocalName(string name, bool isArray) {
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
265 m_localNameStack.Push(m_localName);
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
266 m_localName.localName = name;
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
267 m_localName.isArray = isArray;
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
268 }
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
269
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
270 void RestoreLocalName() {
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
271 m_localName = m_localNameStack.Pop();
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
272 }
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
273
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
274 public override void Close() {
59
21611344d366 code cleanup
cin
parents: 58
diff changeset
275
58
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
276 }
59
21611344d366 code cleanup
cin
parents: 58
diff changeset
277
21611344d366 code cleanup
cin
parents: 58
diff changeset
278 protected override void Dispose(bool disposing) {
21611344d366 code cleanup
cin
parents: 58
diff changeset
279 if (disposing) {
21611344d366 code cleanup
cin
parents: 58
diff changeset
280 m_parser.Dispose();
21611344d366 code cleanup
cin
parents: 58
diff changeset
281 }
21611344d366 code cleanup
cin
parents: 58
diff changeset
282 base.Dispose(disposing);
21611344d366 code cleanup
cin
parents: 58
diff changeset
283 }
21611344d366 code cleanup
cin
parents: 58
diff changeset
284
58
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
285 }
1710dcda34bb Added JSONXmlReader
cin
parents:
diff changeset
286 }