how to write xml in C#.net
-
Hello can anyone help me in getting the xml file's root node in the following format. Here Schedule is root node. I am using the XmlTextWriter class. - Can anyone help me in this regards... Thanks Anee Anee
Show us the code that you got so far and we'll tell you what has to be changed. Don't expect someone to write the whole code for you.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook
-
Show us the code that you got so far and we'll tell you what has to be changed. Don't expect someone to write the whole code for you.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook
Hello, I did, like this.. and got the root element, in the way.. which my sample xml document contains. But i am not much sure, that whether the method that i followed is correct or not. please help me out in fixing whether this is right or not. This the piece of code, which i wrote to write the root node .. according to my requirement.. //writer.WriteStartElement("tns", "schedule", "http://www.MyCopmpany.com/Schedule"); writer.WriteStartElement("tns:schedule"); writer.WriteAttributeString("xmlns:tns", "", "http://www.MyCompany.com/Schedule"); writer.WriteAttributeString("xmlns:dt", "","http://www.MyCompany.com/DataTypes"); writer.WriteAttributeString("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); writer.WriteAttributeString("xsi:schemaLocation", "http://www.MyCompany.com/Schedule Schedule.xsd"); writer.WriteAttributeString("scheduleType", "Playback"); writer.WriteAttributeString("version", "1.0"); writer.WriteAttributeString("creationTime", "2006-01-29T00:00:00"); writer.WriteAttributeString("originator", "MyCompany"); writer.WriteStartElement("scope"); writer.WriteAttributeString("startTime", "2006-01-29T04:00:00".ToString()); writer.WriteAttributeString("stopTime", "2006-01-29T06:00:00".ToString()); writer.WriteEndElement(); //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]; ---- ---- Thank you Anee
-
Hello, I did, like this.. and got the root element, in the way.. which my sample xml document contains. But i am not much sure, that whether the method that i followed is correct or not. please help me out in fixing whether this is right or not. This the piece of code, which i wrote to write the root node .. according to my requirement.. //writer.WriteStartElement("tns", "schedule", "http://www.MyCopmpany.com/Schedule"); writer.WriteStartElement("tns:schedule"); writer.WriteAttributeString("xmlns:tns", "", "http://www.MyCompany.com/Schedule"); writer.WriteAttributeString("xmlns:dt", "","http://www.MyCompany.com/DataTypes"); writer.WriteAttributeString("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); writer.WriteAttributeString("xsi:schemaLocation", "http://www.MyCompany.com/Schedule Schedule.xsd"); writer.WriteAttributeString("scheduleType", "Playback"); writer.WriteAttributeString("version", "1.0"); writer.WriteAttributeString("creationTime", "2006-01-29T00:00:00"); writer.WriteAttributeString("originator", "MyCompany"); writer.WriteStartElement("scope"); writer.WriteAttributeString("startTime", "2006-01-29T04:00:00".ToString()); writer.WriteAttributeString("stopTime", "2006-01-29T06:00:00".ToString()); writer.WriteEndElement(); //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]; ---- ---- Thank you Anee
Looks quite ok, but - For starting the root element you should use the following overload of the WriteStartElement method, cause the one that is currently used expects a local name and not a qualified name:
writer.WriteStartElement("tns", "schedule", "http://www.MyCopmpany.com/Schedule");
- For writing the namespace declarations you should use the following overload, cause the one that is currently used also expects a local name and not a qualified name:
writer.WriteAttributeString("xmlns", "tns", null, "http://www.MyCompany.com/Schedule");
writer.WriteAttributeString("xmlns", "dt", null,"http://www.MyCompany.com/DataTypes");
writer.WriteAttributeString("xmlns", "xsi", null, "http://www.w3.org/2001/XMLSchema-instance");
writer.WriteAttributeString("xsi", "schemaLocation", "http://www.w3.org/2001/XMLSchema-instance", "http://www.MyCompany.com/Schedule Schedule.xsd");
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook
-
Looks quite ok, but - For starting the root element you should use the following overload of the WriteStartElement method, cause the one that is currently used expects a local name and not a qualified name:
writer.WriteStartElement("tns", "schedule", "http://www.MyCopmpany.com/Schedule");
- For writing the namespace declarations you should use the following overload, cause the one that is currently used also expects a local name and not a qualified name:
writer.WriteAttributeString("xmlns", "tns", null, "http://www.MyCompany.com/Schedule");
writer.WriteAttributeString("xmlns", "dt", null,"http://www.MyCompany.com/DataTypes");
writer.WriteAttributeString("xmlns", "xsi", null, "http://www.w3.org/2001/XMLSchema-instance");
writer.WriteAttributeString("xsi", "schemaLocation", "http://www.w3.org/2001/XMLSchema-instance", "http://www.MyCompany.com/Schedule Schedule.xsd");
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook