using System.Collections;
using System.Collections.Generic;
using System.Runtime.Serialization.Formatters;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Serialization;
public static void Test()
string xml = @"<?xml version='1.0' standalone='no'?>
<!ENTITY ent 'Sample text'>
Assert.IsTrue(json2 == json1);
Console.WriteLine("\nXDocument and XmlDocument produce identical results.");
private static string Test2(string xml)
Console.WriteLine("\nTesting XDocument...");
var doc = XDocument.Parse(xml);
string json = JsonConvert.SerializeXNode(doc, Newtonsoft.Json.Formatting.Indented);
private static string Test1(string xml)
Console.WriteLine("\nTesting XmlDocument...");
var settings = new XmlReaderSettings
DtdProcessing = DtdProcessing.Parse,
MaxCharactersFromEntities = (long)1e7,
XmlDocument doc = new XmlDocument();
using (var textReader = new StringReader(xml))
using (var xmlReader = XmlReader.Create(textReader, settings))
string json = JsonConvert.SerializeXmlNode(doc, Newtonsoft.Json.Formatting.Indented);
public static void Main()
Console.WriteLine("Environment version: " + Environment.Version);
Console.WriteLine("Json.NET version: " + typeof(JsonSerializer).Assembly.FullName);
Console.WriteLine("Failed with unhandled exception: ");
public class AssertionFailedException : System.Exception
public AssertionFailedException() : base() { }
public AssertionFailedException(string s) : base(s) { }
public static class Assert
public static void IsTrue(bool value)
public static void IsTrue(bool value, string message)
throw new AssertionFailedException(message ?? "failed");