Does JSonObject has IsNull method? Not having API doc is making the learning harder for me..
{
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);
}
}
> though not as elegant as the one provided by Java library org.jason.* packages
Would you care to expand on which bits you find inelegant or inconvenient?
Try turning off XML namespaces support on the XmlTextReader object by setting its Namespaces property to false.
See attached demo that shows how you can parse the XSD fragment you pasted in your post.
You can also find it online here along with the output JSON:
- Atif
StringWriter
jsonw = new StringWriter();reader.Namespaces =
false; JsonMLCodec.Encode(reader, new JsonTextWriter(jsonw)); JsonArray items = (JsonArray)JsonConvert.Import(jsonw.ToString()); if (items.contains("name") ) ---> returns false
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);
}
}
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();
As I said before, JSON objects become IDictionary objects and JSON arrays become IList objects. These are standard .NET interfaces you need to be familiar with. There is nothing Jayrock-ish about them. You need to get familiar with JsonML and XML gets transformed into it. This is also well-documented at http://jsonml.org. Which other part are you having trouble particular with otherwise?