using System.Xml; XmlDictionaryWriter writer = XmlDictionaryWriter.CreateTextWriter(Console.Out); writer.WriteStartElement("root"); writer.WriteStartElement("child"); writer.WriteString("Hello world"); writer.WriteEndElement(); writer.Flush();
using (XmlDictionaryWriter writer = JsonReaderWriterFactory.CreateJsonWriter(Console.OpenStandardOutput())) { writer.WriteStartElement("root"); writer.WriteStartElement("child"); writer.WriteString("Hello world"); writer.WriteEndElement(); writer.Flush(); }In this example, we create an XmlDictionaryWriter object that writes to a JSON output stream using the JsonReaderWriterFactory class. We then write some XML elements and values to the writer and flush its contents to the console output. Package Library: System.Runtime.Serialization.Xml, Version=4.0.0.0