locked
Root Element is missing RRS feed

  • Question

  • User1776860132 posted
    here is my code , i have a file in root of my site , and its name is : XMLFileForWeather.xml,
    but i dont know why i have recived "Root element is missing"? 
    public partial class MainPage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            
    
            DataSet ds = loadDataSet();
            grdweather.DataSource = ds.Tables[0];
            grdweather.DataBind();
    
                      
        }
    
    
        private DataSet loadDataSet()
        {
            DataSet ds = new DataSet();
    
            ds.ReadXml(Server.MapPath("~/XMLFileForWeather.xml"));
    
            return ds;
        }
      
     
    Thursday, November 17, 2011 7:36 AM

Answers

  • User71929859 posted

    It means your XML is not properly formatted. Open your XML in Visual Studio (Or anyother XML editor) and it will show you the error. Correct the error in your XML file and try again.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, November 17, 2011 9:58 AM

All replies

  • User1049502825 posted

    you need main XML parameter in XML file...means in below example result in root node....

    please use following test file and still you got problem then provide your XML...

    MARK AS ANSWER IF THIS WORKS.....

    <result> 
    <record> 
    <field name='donor_id' id='donor_id' value='1'/> 
    </record>

    <record> 
    <field name='donor_id' id='donor_id' value='2'/> 
    </record>

    </result> 

    Thursday, November 17, 2011 7:41 AM
  • User1776860132 posted

    thank u for your attention , but i did not understand, please tell me with my code.

    Thursday, November 17, 2011 7:44 AM
  • User1049502825 posted

    Please send you XML so i can give in brief.......

    Thursday, November 17, 2011 8:16 AM
  • User-699953111 posted

    U need to declare a XML header. For example: <?xml version="1.0" encoding="utf-8" ?>

    Thursday, November 17, 2011 9:02 AM
  • User-495795224 posted

    Let's say your XML file looks like this:

    <weather>
    <city>New York</city>
    <currentTemp>80</currentTemp>
    <wind>5NE</wind>
    </weather>
    
    <weather>
    <city>Chicago</city>
    <currentTemp>32</currentTemp>
    <wind>20SW</wind>
    </weather>

    You need to wrap your XML elements in a <root> element like this:

    <root>
    
        <weather>
            <city>New York</city>
            <currentTemp>80</currentTemp>
            <wind>5NE</wind>
        </weather>
    
        <weather>
            <city>Chicago</city>
            <currentTemp>32</currentTemp>
            <wind>20SW</wind>
        </weather>
    
    </root>

    It doesn't matter what you call the root element. I called it <root> in attempt to make it easier to see where I made the change.

    Thursday, November 17, 2011 9:09 AM
  • User71929859 posted

    It means your XML is not properly formatted. Open your XML in Visual Studio (Or anyother XML editor) and it will show you the error. Correct the error in your XML file and try again.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, November 17, 2011 9:58 AM