Mercurial > pub > ImplabNet
comparison Implab/Xml/JsonXmlReader.cs @ 264:3a6e18c432be v3
Added XmlToJson xsl transformation.
Added JsonXmlReader.CreateJsonXmlReader(...) methods
Added SerializationHelpers.SerializeJson/DeserializeJson methods
author | cin |
---|---|
date | Mon, 16 Apr 2018 18:43:49 +0300 |
parents | 7c7e9ad6fe4a |
children | 74e048cbaac8 |
comparison
equal
deleted
inserted
replaced
263:711572866e0c | 264:3a6e18c432be |
---|---|
1 using Implab.Formats.Json; | 1 using Implab.Formats.Json; |
2 using System; | 2 using System; |
3 using System.Collections.Generic; | 3 using System.Collections.Generic; |
4 using System.Globalization; | 4 using System.Globalization; |
5 using System.IO; | |
5 using System.Linq; | 6 using System.Linq; |
6 using System.Xml; | 7 using System.Xml; |
7 | 8 |
8 namespace Implab.Xml { | 9 namespace Implab.Xml { |
9 public class JsonXmlReader : XmlReader { | 10 public class JsonXmlReader : XmlReader { |
586 m_jsonSkip = prev.skip; | 587 m_jsonSkip = prev.skip; |
587 | 588 |
588 return !skip; | 589 return !skip; |
589 } | 590 } |
590 | 591 |
592 protected override void Dispose(bool disposing) { | |
593 if (disposing) | |
594 Safe.Dispose(m_parser); | |
595 base.Dispose(true); | |
596 } | |
597 | |
591 public override string ToString() { | 598 public override string ToString() { |
592 switch (NodeType) { | 599 switch (NodeType) { |
593 case XmlNodeType.Element: | 600 case XmlNodeType.Element: |
594 return $"<{Name} {string.Join(" ", (m_attributes ?? new XmlSimpleAttribute[0]).Select(x => $"{x.Prefix}{(string.IsNullOrEmpty(x.Prefix) ? "" : ":")}{x.QName.Name}='{x.Value}'"))} {(IsEmptyElement ? "/" : "")}>"; | 601 return $"<{Name} {string.Join(" ", (m_attributes ?? new XmlSimpleAttribute[0]).Select(x => $"{x.Prefix}{(string.IsNullOrEmpty(x.Prefix) ? "" : ":")}{x.QName.Name}='{x.Value}'"))} {(IsEmptyElement ? "/" : "")}>"; |
595 case XmlNodeType.Attribute: | 602 case XmlNodeType.Attribute: |
604 return $"</{Name}>"; | 611 return $"</{Name}>"; |
605 default: | 612 default: |
606 return $".{NodeType} {Name} {Value}"; | 613 return $".{NodeType} {Name} {Value}"; |
607 } | 614 } |
608 } | 615 } |
616 | |
617 #region static methods | |
618 | |
619 public static JsonXmlReader CreateJsonXmlReader(TextReader textReader, JsonXmlReaderOptions options = null) { | |
620 var jsonReader = JsonReader.Create(textReader); | |
621 return new JsonXmlReader(jsonReader, options); | |
622 } | |
623 | |
624 public static JsonXmlReader CreateJsonXmlReader(Stream stream, JsonXmlReaderOptions options = null) { | |
625 var jsonReader = JsonReader.Create(stream); | |
626 return new JsonXmlReader(jsonReader, options); | |
627 } | |
628 | |
629 public static JsonXmlReader CreateJsonXmlReader(string file, JsonXmlReaderOptions options = null) { | |
630 var jsonReader = JsonReader.Create(file); | |
631 return new JsonXmlReader(jsonReader, options); | |
632 } | |
633 | |
634 #endregion | |
609 } | 635 } |
610 } | 636 } |