Json to Xml Conversion

Dec 10, 2013 at 6:01 AM
I'm creating an application which can access any REST api's. The response from REST can be either json or XML. If I'm receiving Json in below form
Json to xml conversion gives an exception "Document Element is already" present so I change my code
  result = JsonConvert.DeserializeXmlNode(Json).OuterXml   to
  result = JsonConvert.DeserializeXmlNode(Json,RootElement).OuterXml
But for some API calls I received Json as array
In this case the exception was "JsonConver.DeserializeXmlNode will convert only Object" then I changed code to :
result = JsonConvert.DeserializeXmlNode("{\"" + RootElement + "\":" + Json + "}",RootElement).OuterXml;
then the json was converted properly

I need a generic function which converts valid json to xml. How can I achieve this?