Skip to content

Instantly share code, notes, and snippets.

@atifaziz
Created February 3, 2009 08:21
Show Gist options
  • Save atifaziz/57409 to your computer and use it in GitHub Desktop.
Save atifaziz/57409 to your computer and use it in GitHub Desktop.
JsonML with Jayrock
using System;
using System.IO;
using System.Xml;
using Jayrock.Json;
using Jayrock.JsonML;
// See: http://groups.google.com/group/jayrock/t/50be3a3931c39f78
public class Program
{
public static void Main()
{
const string @xml = @"
<div id='demo' class='JSONML'><p>JSONML is a transformation
between<b>JSON</b>and<b>XML</b>that preserves ordering of document
features.</p><p>JSONML can work with JSON arrays or JSON
objects.</p><p>Three<br/>little<br/>words</p></div>";
StringWriter jsonw = new StringWriter();
new JsonMLEncoder().Encode(
new XmlTextReader(new StringReader(xml)),
new JsonTextWriter(jsonw));
Console.WriteLine(jsonw);
StringWriter xmlw = new StringWriter();
new JsonMLDecoder().Decode(
new JsonTextReader(new StringReader(jsonw.ToString())),
new XmlTextWriter(xmlw));
Console.WriteLine(xmlw);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment