using System.Collections.Generic;
using System.Xml.Serialization;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO.Compression;
public static void Test()
static void TestSucceeds()
XmlDocument doc = new XmlDocument();
XmlNodeList nodelist = doc.SelectNodes("*/*");
RemoveChildren(doc.DocumentElement);
Assert.IsTrue(nodelist.Count == 0);
XmlDocument doc = new XmlDocument();
XmlNodeList nodelist = doc.SelectNodes("*/*");
Assert.IsTrue(nodelist.Count > 0);
RemoveChildren(doc.DocumentElement);
Assert.IsTrue(nodelist.Count == 0);
private static XmlNode RemoveChildren(XmlNode n) {
while (n.FirstChild != null)
n.RemoveChild(n.FirstChild);
var xml = @"<mxGraphModel dx=""1086"" dy=""596"" grid=""1"" gridSize=""10"" guides=""1"" tooltips=""1"" connect=""1"" arrows=""1"" fold=""1"" page=""1"" pageScale=""1"" pageWidth=""850"" pageHeight=""1100"" math=""0"" shadow=""0"">
<mxCell id=""1"" parent=""0""/>
<mxCell id=""YJb7HCrh72y2aGPrfETQ-1"" value="""" style=""endArrow=classic;html=1;"" parent=""1"" edge=""1"">
<mxGeometry width=""50"" height=""50"" relative=""1"" as=""geometry"">
<mxPoint x=""130"" y=""310"" as=""sourcePoint""/>
<mxPoint x=""180"" y=""260"" as=""targetPoint""/>
<mxCell id=""YJb7HCrh72y2aGPrfETQ-2"" value="""" style=""endArrow=classic;html=1;"" parent=""1"" edge=""1"">
<mxGeometry width=""50"" height=""50"" relative=""1"" as=""geometry"">
<mxPoint x=""290"" y=""270"" as=""sourcePoint""/>
<mxPoint x=""340"" y=""220"" as=""targetPoint""/>
public static class XmlSerializationHelper
public static T LoadFromXml<T>(this string xmlString, XmlSerializer serial = null)
serial = serial ?? new XmlSerializer(typeof(T));
using (var reader = new StringReader(xmlString))
return (T)serial.Deserialize(reader);
public static string GetXml<T>(this T obj, XmlSerializer serializer = null, bool omitStandardNamespaces = false)
XmlSerializerNamespaces ns = null;
if (omitStandardNamespaces)
ns = new XmlSerializerNamespaces();
using (var textWriter = new StringWriter())
var settings = new XmlWriterSettings() { Indent = true };
using (var xmlWriter = XmlWriter.Create(textWriter, settings))
(serializer ?? new XmlSerializer(obj.GetType())).Serialize(xmlWriter, obj, ns);
return textWriter.ToString();
public static string GetOuterXml(this XmlNode node, bool indent = true)
using (var textWriter = new StringWriter())
var settings = new XmlWriterSettings
OmitXmlDeclaration = true,
using (var xmlWriter = XmlWriter.Create(textWriter, settings))
return textWriter.ToString();
public static void Main()
Console.WriteLine("Environment version: {0} ({1})", System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription , GetNetCoreVersion());
Console.WriteLine("Failed with unhandled exception: ");
public static string GetNetCoreVersion()
var assembly = typeof(System.Runtime.GCSettings).GetTypeInfo().Assembly;
var assemblyPath = assembly.CodeBase.Split(new[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries);
int netCoreAppIndex = Array.IndexOf(assemblyPath, "Microsoft.NETCore.App");
if (netCoreAppIndex > 0 && netCoreAppIndex < assemblyPath.Length - 2)
return assemblyPath[netCoreAppIndex + 1];