XML building off of a schema

JJKazJr

Member
Joined
Jul 28, 2006
Messages
17
Location
Milwaukee, WI
Ok, I am fairly new to .net and do not know how to utilize all of the new features. I am at a point where I have to build a xml file based upon a schema. In the past I would just create nested loops to build the xml. With .Net there are new tools wich I will probably use although I am not sure what is best or if my expectations of them are reasonable so any guidence would be useful.

xml writer...seems like the same way as I am used to but with different tags to help see what is going on.

xml datadocument..not too sure how this works

dataset...load in the schema creates multiple tables but I am unsure how to insert the related data.

These are the things that I have been looking at. Suggestions about what path I should look into or a differnt way I should learn would be useful. Im sure there are plenty of ways to do this I was just wondering what way was the best(fastest,easiest, most versitle).

Thank you.
 
XmlDocument is just a managed representation of the underlying textual xml.

DataSets can have multiple DataTable instances. To add a row to a particular table you can just do:
C#:
DataTable dt = myDataSet.Tables[0];
dt.Rows.Add(x,y,z);
You might find the "GetXml()" method of the DataSet class useful.
 
Yes, I know that I can add rows to a datatable as you have shown, I just dont know how to easily relate the all the data between the tables. Lets say I read an xml schema into a dataset, the structure it creates would be similar to:
datatable[1]
datatable[2]​
datatable[3]​
datatable....​
when look at from the xml. Table 1s columns all corespond to the first elements and attributs, while the second would be the indented, sub categores, the third(subcatagores of the second) and so on. If I were to put data into datatable[3], is there an easy way to relate that back up to data already resideing in datatable[1] or would i have to work my way up, down the structure searching for the values of the relations and using them? That is what I was trying to get at.
Thank you for the reply, I like all the input I can get, I just cant seem to get a lot at this forum.
 
Last edited by a moderator:
If you are using a DataSet then you can add a DataRelation to it via the DataSets Relations property - this will allow you to programatically navigate the relationship.

If you have the .xsd that defines the schema then you can add this to your .Net project and VS will build a code model around the schema for you.
 
Back
Top