Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. XML / XSL
  4. ASP.Net : Xml Version Format

ASP.Net : Xml Version Format

Scheduled Pinned Locked Moved XML / XSL
questionxmlcsharpasp-netdatabase
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    Vijay Jadhav India
    wrote on last edited by
    #1

    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

    S 1 Reply Last reply
    0
    • V Vijay Jadhav India

      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

      S Offline
      S Offline
      Samer Aburabie
      wrote on last edited by
      #2

      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 !

      V 1 Reply Last reply
      0
      • S Samer Aburabie

        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 !

        V Offline
        V Offline
        Vijay Jadhav India
        wrote on last edited by
        #3

        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.

        G 1 Reply Last reply
        0
        • V Vijay Jadhav India

          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.

          G Offline
          G Offline
          George L Jackson
          wrote on last edited by
          #4

          You can use XmlWriter with XmlWriterSettings:

          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

          V 1 Reply Last reply
          0
          • G George L Jackson

            You can use XmlWriter with XmlWriterSettings:

            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

            V Offline
            V Offline
            Vijay Jadhav India
            wrote on last edited by
            #5

            Hi, Thanks for your snippet. :)

            Vijay Jadhav.

            V 1 Reply Last reply
            0
            • V Vijay Jadhav India

              Hi, Thanks for your snippet. :)

              Vijay Jadhav.

              V Offline
              V Offline
              Vijay Jadhav India
              wrote on last edited by
              #6

              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.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups