1

I realize that there is a similar question here: How to deserialize xml to object

But this is not the same. In my case the object I am trying to deserialize is not xml, it is a class that represents data I would like to assign to my xml.

I have xml data that looks like this:

<?xml version="1.0"?>
<grouping>
   <item>
      <book>book text</book>
      <title>title text</title>
      <genre>
         <subitem>subitem name</subitem>
      </genre>
   </item>
   <part>
      <name>Doe, John/name>
      <description>desc text</description>
      <detail>detail text</detail>
   </part>
</grouping>

I have class that looks like this:

public class DataRow{
   public string book;
   public string title;
   public string subitem;
   public string name;
   public string description;
   public string detail;
}

I'm deserializing my data base data to the class so that I have an instance of it such as dr. I can now do dr.book,dr.title, etc...

How can I deserialize my DataRow class instance (dr) to the XML?

mo_maat
  • 2,110
  • 12
  • 44
  • 72
  • There are mixed signals in this question. Do you just want to serialize `DataRow` as XML that looks like the XML above? The reason I'm confused is because you mention how you're *loading* the XML, but I don't follow what that has to do with *writing* the XML. You also mention "serializing" data to the class. Do you mean deserializing? If those details are relevant then they need some explanation so we can understand them. If they're not relevant and you just want to write the data as XML, then perhaps you could delete the irrelevant parts to avoid confusion. – Scott Hannen Jun 19 '19 at 20:24
  • Do you want to serialize `XML` to an object or the other way round? – Sach Jun 19 '19 at 20:29
  • @ScottHannen I see your confusion. Yes, I want to serialize `DataRow` as XML that looks like the XML template. By loading the XML I just meant I was doing that to work on a way to find a solution. Yes, I mean deserializing data to the class. That was a typo. – mo_maat Jun 19 '19 at 20:57

0 Answers0