Root element is missing

前端 未结 6 2004
离开以前
离开以前 2020-12-06 05:52

I am reading xml from xxx URl but i am getting error as Root element is missing.

My code to read xml response is as follows:

  XmlDocument doc = new          


        
6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-06 06:03

    Hi this is odd way but try it once

    1. Read the file content into a string
    2. print the string and check whether you are getting proper XML or not
    3. you can use XMLDocument.LoadXML(xmlstring)

    I try with your code and same XML without adding any XML declaration it works for me

    XmlDocument doc = new XmlDocument();
            doc.Load(@"H:\WorkSpace\C#\TestDemos\TestDemos\XMLFile1.xml");
            XmlNodeList nodes = doc.GetElementsByTagName("Product");
            XmlNode node = null;
            foreach (XmlNode n in nodes)
            {
                Console.WriteLine("HI");
            }
    

    Its working perfectly fine

提交回复
热议问题