Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You cant get an XML file like that from using 'DataSet.WriteXML'.</p> <p>You could implement your own custom WriteXML function that derives from the 'ISerializeable' interface. This is probably a good idea if you are building a database or going to want a lot of control over how your data is serialized. Here is an <a href="http://www.codeproject.com/Articles/43237/How-to-Implement-IXmlSerializable-Correctly" rel="nofollow">example on CodeProject</a>.</p> <p>How bad do you really need a DataTable? Are you going to be using SQL? Do you need relations?</p> <p>If your goal is, as you say, to generate an XML file that exactly matches your example, you might want to start by storing your data in a class:</p> <pre><code>public class BrickTable { public int Value { get; set; } public string Title { get; set; } public int X { get; set; } public int Y { get; set; } [XmlArrayItem("ItemType")] public List&lt;string&gt; Items { get; set; } public BrickTable() { } } </code></pre> <p><br /></p> <p>Note: Items can be a list of string, a list of Type, or your own custom class:</p> <pre><code>public class Item { public string Name { get; set; } public string Type { get; set; } public int Value { get; set; } public Item() { } } </code></pre> <p><br /></p> <p>And its serializing function:</p> <pre><code>public void SerializeObject(string filename,object obj) { using(StreamWriter streamWriter = new StreamWriter(filename)) { XmlSerializer xmlSerializer = new XmlSerializer(obj.GetType()); xmlSerializer.Serialize(streamWriter,obj); } } </code></pre> <p><br /></p> <p>Usage:</p> <pre><code>void Test() { BrickTable bTable = new BrickTable(); bTable.Title = ""; bTable.Value = 23039; bTable.X = 18400; bTable.Y = 64; List&lt;string&gt; items = new List&lt;string&gt;(); items.Add("Item1"); items.Add("Item5"); bTable.Items = items; SerializeObject("BrickSet.xml",bTable); } </code></pre> <p>Finally, you can make a function that takes a data row and returns a filled out a BrickTable class, or you can convert a class into a DataTable using reflection, <a href="http://csharpcodewhisperer.blogspot.com/2013/07/class-to-datatable.html" rel="nofollow">as shown here</a>.</p> <p>So the question is, how badly do you need your XML to be formatted in that way? Does it also need to be in the form of a DataTable, also?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload