none
XML to DataSet RRS feed

  • Question

  • Hi,
    How can i covert the below structure to a dataset  in asp.net.

    <?xml version="1.0" encoding="utf-8"?>

    <Country>

    <CountryName>India</CountryName>

    <CountryID>76</CountryID>

    <CountryCode>91</CountryCode>

    <States>

                <StateName>Maharastra</StateName>

                <StateID>563</StateID>

                <Districts>

    <Option>         

                                        <Sequence>1</Sequence>

                                        <Desc>Mumbai</Desc>

    </Option>        

    <Option>         

                                        <Sequence>2</Sequence>

                                        <Desc>Andheri</Desc>

    </Option>        

                </Districts>

                <Airport>Yes</Airport>

                <Railways>Yes</Railways>

                <Harbour>Yes</Harbour>         

    </States>

     

    <States>

                <StateName>Maharastra</StateName>

                <StateID>563</StateID>

                <Districts>

    <Option>         

                                        <Sequence>1</Sequence>

                                        <Desc>Mumbai</Desc>

    </Option>        

    <Option>         

                                        <Sequence>2</Sequence>

                                        <Desc>Andheri</Desc>

    </Option>        

                </Districts>

                <Airport>Yes</Airport>

                <Railways>Yes</Railways>

                <Harbour>Yes</Harbour>         

    </States>

    </Country>




    knowledge glows
    • Moved by John Saunders Friday, March 6, 2009 2:08 PM DataSet, not WS (Moved from ASMX Web Services and XML Serialization to ADO.NET DataSet)
    Thursday, March 5, 2009 5:45 PM

Answers

  • Hi

    Because quoted XML has few levels you have to do it manually if you want to add all of them.
    Here is a simple tutorial about 

    if this is not the case you could use a simple binding like:
       string myXMLfile = @"C:\MySchema.xml";  
        DataSet ds = new DataSet();  
        // Create new FileStream with which to read the schema.  
        System.IO.FileStream fsReadXml = new System.IO.FileStream   
            (myXMLfile, System.IO.FileMode.Open);  
        try  
        {  
            ds.ReadXml(fsReadXml);  
            dataGrid1.DataSource = ds;  
            dataGrid1.DataMember = "Districts";  // for instance
        }  
        catch (Exception ex)  
        {  
        MessageBox.Show(ex.ToString());  
        }  
        finally  
        {  
        fsReadXml.Close();  
        }  
     

    HTH

    Ivo Stoykov
    Monday, March 9, 2009 6:36 AM