Skip to content

Instantly share code, notes, and snippets.

@atifaziz
Created February 20, 2009 08:26
Show Gist options
  • Save atifaziz/67375 to your computer and use it in GitHub Desktop.
Save atifaziz/67375 to your computer and use it in GitHub Desktop.
[
"xs:complexType",
{
"name": "MyRequest"
},
[
"xs:annotation",
[
"xs:documentation",
"\r\n This is the sample message\r\n"
]
],
[
"xs:sequence",
[
"xs:element",
{
"minOccurs": "1",
"name": "requestEnvelope",
"type": "common:RequestEnvelope"
}
],
[
"xs:element",
{
"minOccurs": "1",
"maxOccurs": "1",
"name": "email",
"type": "xs:string"
}
],
[
"xs:element",
{
"minOccurs": "0",
"maxOccurs": "1",
"name": "transactionId",
"type": "xs:string"
}
],
[
"xs:element",
{
"minOccurs": "0",
"maxOccurs": "1",
"name": "trackingId",
"type": "xs:string"
}
],
[
"xs:any",
{
"maxOccurs": "unbounded",
"minOccurs": "0",
"namespace": "##other",
"processContents": "lax"
}
]
]
]
using System;
using System.IO;
using System.Xml;
using Jayrock.Json;
using Jayrock.JsonML;
public class Program
{
public static void Main()
{
const string @xml = @"
<xs:complexType name='MyRequest'>
<xs:annotation>
<xs:documentation>
This is the sample message
</xs:documentation>
</xs:annotation>
<xs:sequence>
<xs:element minOccurs='1' name='requestEnvelope'
type='common:RequestEnvelope' />
<xs:element minOccurs='1' maxOccurs='1'
name='email' type='xs:string' />
<xs:element minOccurs='0' maxOccurs='1' name='transactionId' type='xs:string'/>
<xs:element minOccurs='0' maxOccurs='1' name='trackingId' type='xs:string'/>
<xs:any maxOccurs='unbounded' minOccurs='0'
namespace='##other' processContents='lax' />
</xs:sequence>
</xs:complexType>";
StringWriter jsonw = new StringWriter();
XmlTextReader reader = new XmlTextReader(new StringReader(xml));
reader.Namespaces = false;
JsonMLCodec.Encode(reader, new JsonTextWriter(jsonw));
Console.WriteLine(jsonw);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment