Beispiel #1
0
        private XmlNode DeserializeXmlNode(string json, string deserializeRootElementName)
        {
            JsonTextReader reader;

            reader = new JsonTextReader(new StringReader(json));
            reader.Read();
            XmlNodeConverter converter = new XmlNodeConverter();

            if (deserializeRootElementName != null)
            {
                converter.DeserializeRootElementName = deserializeRootElementName;
            }

            XmlNode node = (XmlNode)converter.ReadJson(reader, typeof(XmlDocument), null, new JsonSerializer());

#if !NET20
            string xmlText = node.OuterXml;

            reader = new JsonTextReader(new StringReader(json));
            reader.Read();
            XDocument d = (XDocument)converter.ReadJson(reader, typeof(XDocument), null, new JsonSerializer());

            string linqXmlText = d.ToString(SaveOptions.DisableFormatting);
            if (d.Declaration != null)
            {
                linqXmlText = d.Declaration + linqXmlText;
            }

            Assert.AreEqual(xmlText, linqXmlText);
#endif

            return(node);
        }
Beispiel #2
0
    public override DataSet ReadJson(JsonReader reader, Type objectType, DataSet existingValue, bool hasExistingValue, JsonSerializer serializer)
    {
        var converter = new XmlNodeConverter {
            OmitRootObject = false
        };
        var document = (XDocument)converter.ReadJson(reader.MoveToContent(), typeof(XDocument), null, serializer);

        using (var xmlReader = document.CreateReader())
        {
            var dataSet = new DataSet();
            dataSet.ReadXml(xmlReader);
            return(dataSet);
        }
    }
        /// <summary>
        /// Initializes a new instance of the <see cref="JsonInterpreter"/> class.
        /// </summary>
        /// <param name="source">The <see cref="IResource"/>.</param>
        public JsonInterpreter(IResource source) : base(source)
        {
            string xmlContents = string.Empty;

            using (source)
            {
                JsonReader reader = new JsonTextReader(new StreamReader(source.Stream));
                reader.Read();

                XmlNodeConverter toXml  = new XmlNodeConverter();
                XmlDocument      xmlDoc = (XmlDocument)toXml.ReadJson(reader, typeof(XmlDocument));
                xmlContents = xmlDoc.OuterXml;
                reader.Close();
            }

            IResource resource = new StaticContentResource(xmlContents);

            xmlInterpreter = new XmlConfigurationInterpreter(resource);
        }
    private XmlNode DeserializeXmlNode(string json, string deserializeRootElementName)
    {
      JsonTextReader reader;

      reader = new JsonTextReader(new StringReader(json));
      reader.Read();
      XmlNodeConverter converter = new XmlNodeConverter();
      if (deserializeRootElementName != null)
        converter.DeserializeRootElementName = deserializeRootElementName;

      XmlNode node = (XmlNode)converter.ReadJson(reader, typeof (XmlDocument), null, new JsonSerializer());

#if !NET20
     string xmlText = node.OuterXml;

      reader = new JsonTextReader(new StringReader(json));
      reader.Read();
      XDocument d = (XDocument) converter.ReadJson(reader, typeof (XDocument), null, new JsonSerializer());

      string linqXmlText = d.ToString(SaveOptions.DisableFormatting);
      if (d.Declaration != null)
        linqXmlText = d.Declaration + linqXmlText;

      Assert.AreEqual(xmlText, linqXmlText);
#endif

      return node;
    }