title: Is it possible to use JsonReaderWriterFactory to convert XML to JSON without using DataContractJsonSerializer?
body: <p>I need a generic routine that takes any valid XML and converts it to JSON without knowing the underlying data type. I know that this is easily done with Json.Net and I also know how to do it with the DataContractJsonSerializer but our organisation doesn't use Json.Net and the DataContractJsonSerializer needs a Data Contract enabled object type.</p>
  
  <p>My working code using Json.Net:</p>
  
  <pre><code>XmlDocument document = new XmlDocument();
  document.LoadXml(xml);
  string jsonText = JsonConvert.SerializeXmlNode(document);
  </code></pre>
  
  <p>The code I'd like to be able to use, using JsonReaderWriterFactory instead of Json.Net:</p>
  
  <pre><code>string jsonText = string.Empty;
  
  MemoryStream stream = new MemoryStream();
  StreamWriter streamWriter = new StreamWriter(stream);
  streamWriter.Write(xml);
  streamWriter.Flush();
  stream.Position = 0;
  
  using (XmlDictionaryWriter xmlWriter = JsonReaderWriterFactory.CreateJsonWriter(stream))
  {
      object someObject = new object();
      DataContractJsonSerializer serializer = new DataContractJsonSerializer(someObject.GetType());
      serializer.WriteObject(stream, someObject);
      xmlWriter.Flush();
      jsonText = Encoding.Default.GetString(stream.GetBuffer());
  }
  </code></pre>
  
  <p>Is there a way around this?</p>