0

I tried to convert a hashtable to XML like this, but it didn't work:

   var jsonArray = new List<Hashtable>();
   XmlNode xml = JsonConvert.DeserializeXmlNode("{\"Row\":" + jsonArray + "}", 
  "BiddingHistory");
Stefan
  • 17,448
  • 11
  • 60
  • 79
Prince
  • 43
  • 9
  • 1
    tried the above it didn't work, l have a hashtable list that l want to convert to xml , am happy with what ever works – Prince Oct 26 '18 at 12:21
  • You don't need to go from json to xml, you can go straight to xml. [See this](https://stackoverflow.com/questions/4123590/serialize-an-object-to-xml). If you want to nest the result in a `Row` element you will need to [manipulate the xml after serialization](https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/linq/creating-xml-trees-linq-to-xml-2). It would also be pretty easy to loop over your list and create nodes as per second link without using `XmlSerializer`. – Crowcoder Oct 26 '18 at 12:49
  • 1
    try this => https://stackoverflow.com/questions/6202780/convert-hashtable-to-xml-string-and-back-to-hashtable-without-using-net-seriali – er-sho Oct 26 '18 at 13:15

1 Answers1

0

Thank you for your contributions l ended up converting the hash table into a datatable then from a Data table to xml.

  using (StringWriter sw = new StringWriter())
        {
            dataTable.WriteXml(sw);
            xml = sw.ToString();
            xml = xml.Replace("DocumentElement", "ArrayOfDataEDI");
        } 
Prince
  • 43
  • 9