ASP.Net : Xml Version Format
-
Hi Experts, My Xml format is :
<Sis>
<Student>
<StudentID>1</StudentID>
<AcademicDetails>2008-2009</AcademicDetails>
<PersonalDetails>
<FirstName>Vijay</FirstName>
<MiddleName>Laxmanrao</MiddleName>
<LastName>Jadhav</LastName>
</PersonalDetails>
</Student>
</Sis>I have seen lot of Xml's with Version information ie <? xml version="1.0" ?>. My question is that what is a cause that my Xml didn't show version and other information. My Sample code behind for creating Xml is :
#region Create Student Xml String /\* ---------------------------------------------------------- Create Student Xml File --------------------------------------------------------------------- \*/ private string sCreateStudentXml() { try { Consumer.Sis studentDS = new Consumer.Sis(); Sis.StudentRow student\_row = studentDS.Student.NewStudentRow(); student\_row.StudentID = 1; student\_row.AcademicDetails = "2008-2009"; studentDS.Student.AddStudentRow(student\_row); Sis.PersonalDetailsRow sub\_StudentPersonalDetails\_row = studentDS.PersonalDetails.NewPersonalDetailsRow(); sub\_StudentPersonalDetails\_row.FirstName = "Vijay"; sub\_StudentPersonalDetails\_row.MiddleName = "Laxmanrao"; sub\_StudentPersonalDetails\_row.LastName = "Jadhav"; sub\_StudentPersonalDetails\_row.StudentRow = student\_row; studentDS.PersonalDetails.AddPersonalDetailsRow(sub\_StudentPersonalDetails\_row); // Accept the changes studentDS.AcceptChanges(); System.IO.StringWriter writer = new System.IO.StringWriter(); studentDS.WriteXml(writer, System.Data.XmlWriteMode.WriteSchema); return writer.ToString(); } catch (Exception ex) { throw ex; } } #endregion
And my Xsd is :
<?xml version="1.0" encoding="utf-8" ?>
<!--Created with Liquid XML Studio - 30 Day Trial Edition (http://www.liquid-technologies.com)-->
<xsd:schema id="Sis" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:complexType name="StudentPersonalDetails">
xsd:sequence -
Hi Experts, My Xml format is :
<Sis>
<Student>
<StudentID>1</StudentID>
<AcademicDetails>2008-2009</AcademicDetails>
<PersonalDetails>
<FirstName>Vijay</FirstName>
<MiddleName>Laxmanrao</MiddleName>
<LastName>Jadhav</LastName>
</PersonalDetails>
</Student>
</Sis>I have seen lot of Xml's with Version information ie <? xml version="1.0" ?>. My question is that what is a cause that my Xml didn't show version and other information. My Sample code behind for creating Xml is :
#region Create Student Xml String /\* ---------------------------------------------------------- Create Student Xml File --------------------------------------------------------------------- \*/ private string sCreateStudentXml() { try { Consumer.Sis studentDS = new Consumer.Sis(); Sis.StudentRow student\_row = studentDS.Student.NewStudentRow(); student\_row.StudentID = 1; student\_row.AcademicDetails = "2008-2009"; studentDS.Student.AddStudentRow(student\_row); Sis.PersonalDetailsRow sub\_StudentPersonalDetails\_row = studentDS.PersonalDetails.NewPersonalDetailsRow(); sub\_StudentPersonalDetails\_row.FirstName = "Vijay"; sub\_StudentPersonalDetails\_row.MiddleName = "Laxmanrao"; sub\_StudentPersonalDetails\_row.LastName = "Jadhav"; sub\_StudentPersonalDetails\_row.StudentRow = student\_row; studentDS.PersonalDetails.AddPersonalDetailsRow(sub\_StudentPersonalDetails\_row); // Accept the changes studentDS.AcceptChanges(); System.IO.StringWriter writer = new System.IO.StringWriter(); studentDS.WriteXml(writer, System.Data.XmlWriteMode.WriteSchema); return writer.ToString(); } catch (Exception ex) { throw ex; } } #endregion
And my Xsd is :
<?xml version="1.0" encoding="utf-8" ?>
<!--Created with Liquid XML Studio - 30 Day Trial Edition (http://www.liquid-technologies.com)-->
<xsd:schema id="Sis" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:complexType name="StudentPersonalDetails">
xsd:sequenceWhy don't you just use it as it is ? Is it causing you problems ?!
Sincerely Samer Abu Rabie Imagination is more important than knowledge !
-
Why don't you just use it as it is ? Is it causing you problems ?!
Sincerely Samer Abu Rabie Imagination is more important than knowledge !
Hi Samer, Thanks for reply. Because the XML declaration like : xmlns:xs="http://www.w3.org/2001/XMLSchema". I am going to use later. The purpose is to identify, Xml based on Xsd. Any solution ? :^)
Vijay Jadhav.
-
Hi Samer, Thanks for reply. Because the XML declaration like : xmlns:xs="http://www.w3.org/2001/XMLSchema". I am going to use later. The purpose is to identify, Xml based on Xsd. Any solution ? :^)
Vijay Jadhav.
You can use
XmlWriter
withXmlWriterSettings
:XmlWriterSettings settings = new XmlWriterSettings();
settings.OmitXmlDeclaration = false;
settings.Indent = true;XmlWriter xmlWriter = xmlWriter = XmlWriter.Create(
@"c:\temp\temp.xml", settings);studentDS.WriteXml(xmlWriter);
xmlWriter.Close();"We make a living by what we get, we make a life by what we give." --Winston Churchill
modified on Tuesday, May 19, 2009 12:27 PM
-
You can use
XmlWriter
withXmlWriterSettings
:XmlWriterSettings settings = new XmlWriterSettings();
settings.OmitXmlDeclaration = false;
settings.Indent = true;XmlWriter xmlWriter = xmlWriter = XmlWriter.Create(
@"c:\temp\temp.xml", settings);studentDS.WriteXml(xmlWriter);
xmlWriter.Close();"We make a living by what we get, we make a life by what we give." --Winston Churchill
modified on Tuesday, May 19, 2009 12:27 PM
Hi, Thanks for your snippet. :)
Vijay Jadhav.
-
Hi, Thanks for your snippet. :)
Vijay Jadhav.
Hi all, We have done it. Please view the following code snippet : #region Create Student Xml String /* Create Student Xml File */ private string sCreateStudentXml() { try { Consumer.Sis studentDS = new Consumer.Sis(); Sis.StudentRow student_row = studentDS.Student.NewStudentRow(); student_row.StudentID = 1; student_row.AcademicDetails = "2008-2009"; studentDS.Student.AddStudentRow(student_row); Sis.PersonalDetailsRow sub_StudentPersonalDetails_row = studentDS.PersonalDetails.NewPersonalDetailsRow(); sub_StudentPersonalDetails_row.FirstName = "Vijay"; sub_StudentPersonalDetails_row.MiddleName = "Laxmanrao"; sub_StudentPersonalDetails_row.LastName = "Jadhav"; sub_StudentPersonalDetails_row.StudentRow = student_row; studentDS.PersonalDetails.AddPersonalDetailsRow(sub_StudentPersonalDetails_row); // Accept the changes studentDS.AcceptChanges(); System.IO.StringWriter writer = new System.IO.StringWriter(); studentDS.WriteXml(writer, System.Data.XmlWriteMode.IgnoreSchema); XmlDocument doc = new XmlDocument(); doc.LoadXml(writer.ToString()); XmlNode root = doc.DocumentElement; XmlAttribute att = doc.CreateAttribute("xsi", "noNamespaceSchemaLocation", "http://www.w3.org/2001/XMLSchema-instance"); att.Value = "Sis.xsd"; root.Attributes.Append(att); writer = new System.IO.StringWriter(); doc.Save(writer); string sXML = writer.ToString(); sXML = sXML.Replace("utf-16", "utf-8"); return sXML.ToString(); } catch (Exception ex) { throw ex; } } #endregion Thanks all for being with me! :)
Vijay Jadhav.