0

I get my data retrieved in this way

var parentData = dataContext.Fetch<MakerCheckerViewModel>  
(PetaPoco.Sql.Builder.Append  
  ("SELECT MakerCheckerId  
  ,ModelName  
  ,mkCk.CheckerStatusId  
  ,chkSt.CheckerStatusName  
  FROM MakerChecker as mkCk  
  JOIN CheckerStatus as chkSt ON  
mkCk.CheckerStatusId=chkSt.CheckerStatusId")  
).ToList();  

I need to convert it into json. I referred these links How to convert JSON to XML or XML to JSON? but using this it can convert only the string data but not the list types.
Also I cannot do it inside Linq as done here convert list to xml in c# as I have the bunch data which will be increasing more in future so I need something like this

    var parentDataJson = JsonConvert.SerializeObject(parentData);

which is done to convert to json. So similar functionality would be there for xml data too. Please help!!

Community
  • 1
  • 1
khushbu
  • 567
  • 2
  • 8
  • 24

1 Answers1

0

This will return a string of XML.

public string CreateXml(MyObject myObject)
{
    var xmlDoc = new XmlDocument();

    var xmlSerializer = new XmlSerializer(myObject.GetType());

    using (var xmlStream = new MemoryStream())
    {
        xmlSerializer.Serialize(xmlStream, myObject);
        xmlStream.Position = 0;
        xmlDoc.Load(xmlStream);
        return xmlDoc.InnerXml;
    }
}
Fatih Ayyildiz
  • 367
  • 3
  • 14