Xmlfile into Datalist

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sreelucky
    New Member
    • Mar 2007
    • 5

    Xmlfile into Datalist

    Reading xmlfile into a datalist or reapeter countrol specially in .net2003
    and also how do we read it in .net2005
    Last edited by sreelucky; Mar 8 '07, 10:36 AM. Reason: for more clarity
  • avkdsiva
    New Member
    • Mar 2007
    • 23

    #2
    Originally posted by sreelucky
    Reading xmlfile into a datalist or reapeter countrol specially in .net2003
    and also how do we read it in .net2005
    why dont you try to load the xmlfile into a dataset and then, adding that dataset as a DataSource for Datalist of repeater control?
    FYI, to load the xmlfile into a dataset, you should have schema file that has the schema information of that xmlfile

    Comment

    • sreelucky
      New Member
      • Mar 2007
      • 5

      #3
      Thank You for your Response, But i already tried it as
      First i had an xml.file
      i took an object of a dataset
      an then i read the xml file into dataset using readxml method of the dataset
      and then i set the datalist datasource to the dataset
      but it is not working.
      plz help me....

      Comment

      • avkdsiva
        New Member
        • Mar 2007
        • 23

        #4
        what error, are you getting and when are you getting?while populating dataset ? or after populating it?

        Comment

        • sreelucky
          New Member
          • Mar 2007
          • 5

          #5
          Hi
          the thing is i don't have database in my system so i tried with xml to fill the dtagrid with that xmlfile,
          first i added an xml file and i have writen something like as followes

          <?xml version="1.0" encoding="utf-8" ?>
          <countries>
          <country name="india">
          <capital>Delh i</capital>
          </country>
          <country name="SriLanka" >
          <capital>Colomb o</capital>
          </country>
          <country name="nepal">
          <capital>khatma ndu</capital>
          </country>
          </countries>


          I want to populate my datagrid with this data....
          it is asking me something about xsd,xslt
          to read xml file do we need to go with xsd & xslt .. what is the relation among those(.xml,.xsd ,.xslt)

          I am a begineer in .net.

          so kindly help me in doing this,

          thank you.

          Comment

          • sreelucky
            New Member
            • Mar 2007
            • 5

            #6
            the error it displayes
            -----------------------------------------------
            Could not find file "C:\WINDOWS\sys tem32\countryCa pital.xml".

            Comment

            • sreelucky
              New Member
              • Mar 2007
              • 5

              #7
              will u please explain breafly
              how should be the xml schema.
              for the following .xml file...


              <?xml version="1.0" encoding="utf-8" ?>
              <countries>
              <country name="india">
              <capital>Delh i</capital>
              </country>
              <country name="SriLanka" >
              <capital>Colomb o</capital>
              </country>
              <country name="nepal">
              <capital>khatma ndu</capital>
              </country>
              </countries>
              thank you

              Comment

              • avkdsiva
                New Member
                • Mar 2007
                • 23

                #8
                Originally posted by sreelucky
                will u please explain breafly
                how should be the xml schema.
                for the following .xml file...


                <?xml version="1.0" encoding="utf-8" ?>
                <countries>
                <country name="india">
                <capital>Delh i</capital>
                </country>
                <country name="SriLanka" >
                <capital>Colomb o</capital>
                </country>
                <country name="nepal">
                <capital>khatma ndu</capital>
                </country>
                </countries>
                thank you
                You need to create xsd file for the xml file that you have.
                in VS.NET environment, open the XML file and right click on any part of the data. You can see "Create Schema" Option there. Click on that and VS will create an xsd file for you. Only thing you need to do is change the second line of your xml file as
                <countries xmlns="http://tempuri.org/testFile1.xsd">


                Following method can be used for retriving a Dataset from an XML file
                private DataSet getXmlDataSet(s tring xmlFileName,str ing xmlSchemaFile)
                {
                XmlDataDocument xmlFile = new XmlDataDocument ();
                DataSet ds = new DataSet();
                try
                {
                xmlFile.DataSet .ReadXmlSchema( xmlSchemaFile);
                XmlTextReader TrainReader = new XmlTextReader(x mlFileName);
                TrainReader.Mov eToContent();
                xmlFile.Load(Tr ainReader);
                ds = xmlFile.DataSet ;
                }
                catch (Exception e)
                {
                ds.Dispose();
                MessageBox.Show (this,e.Message ,"Error");
                }
                return ds;
                }


                Let me know if you have any problem.

                Comment

                Working...