writing XML in C#.net
-
hello, I am new to both the xml and C#.net technologies. I am generating a xml file in c#.net.I am trying to generate a xml file whose first/root node should look like this: I am using the xmlWriter class to generate the xml. The data for xml is taken from the structure which is filled by the program itself. My code is as follows: private void generateXml() { TreeNode tempNode,selectedNode; frmFindByProgram.stProgram stTemp = new frmFindByProgram.stProgram(); selectedNode=new TreeNode(); tempNode = new TreeNode(); XmlTextWriter writer = new XmlTextWriter("E:\\Projects\\Project1\\July\\26\\ScheduleDemo\\NewXML.xml", new System.Text.UTF8Encoding()); //Write the header information writer.WriteStartDocument(); //Write the root node writer.WriteStartElement("tns", "schedule","http://www.sample.com/Schedule"); //use the record structure int i = 0, count; count = xmlSlotNodes.Count; // sort the slots according to there callSign xmlSlotNodes.Sort(0,count,new Sorting ()); string[] prgmTime = new string[2]; stTemp = (frmFindByProgram.stProgram)xmlSlotNodes[i]; selectedNode=getClickedNode(); writer.Formatting = Formatting.Indented; writer.WriteStartElement("CruiseLine"); // writer.WriteAttributeString("Id", selectedNode.Text ); writer.WriteAttributeString ("Name",selectedNode.Parent.Text); writer.WriteStartElement("Ship"); writer.WriteAttributeString("Name", selectedNode.Text ); writer.WriteStartElement("Channel"); writer.WriteStartElement("CallSign"); writer.WriteAttributeString("Value", stTemp.CallSign); prgmTime = stTemp.Duration.Split('-'); do { stTemp = (frmFindByProgram.stProgram)xmlSlotNodes[i]; pr