Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7779137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:34:30+00:00 2026-06-01T18:34:30+00:00

I am reading xml from xxx URl but i am getting error as Root

  • 0

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 XmlDocument();
  doc.Load("URL from which i am reading xml");
  XmlNodeList nodes = doc.GetElementsByTagName("Product");
  XmlNode node = null;
  foreach (XmlNode n in nodes)
   {
   }

and the xml response is as follows:

<All_Products>
   <Product>
  <ProductCode>GFT</ProductCode>
  <ProductName>Gift Certificate</ProductName>
  <ProductDescriptionShort>Give the perfect gift. </ProductDescriptionShort>
  <ProductDescription>Give the perfect gift.</ProductDescription>
  <ProductNameShort>Gift Certificate</ProductNameShort> 
  <FreeShippingItem>Y</FreeShippingItem>
  <ProductPrice>55.0000</ProductPrice>
  <TaxableProduct>Y</TaxableProduct>
   </Product>    
 </All_Products>

Can you please tell where i am going wrong.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T18:34:32+00:00Added an answer on June 1, 2026 at 6:34 pm

    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");
            }
    

    As stated by Phil in below answer please set the xmlStream position to zero if it is not zero.

    if (xmlStream.Position > 0)
    {
        xmlStream.Position = 0;
    }
    XDocument xDoc = XDocument.Load(xmlStream); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to read a xml from a service url, I wrote the code,
I am reading attempting to load XML from a ByteArray as follows: var xmlString:String
Reading outer Xml from an XmlReader , how do I remove whitespaces(\n\t\t) in my
I'm reading XML data from the HttpServletRequest in my servlets doPost() and passing the
I am reading data from XML like this: (Contacts.xml) <?xml version=1.0 encoding=utf-8 standalone=yes?> <!--LINQ
I'm reading an xml file and want to make it from a relative directory
I planning on reading profile data from a xml file in JSP. Now i
My asp.net web application is reading and decrypting the password from a XML file
I used HTTPService for reading xml, but I want only a particular xml field
I have a problem reading OWL/XML files from Java using Jena. I have no

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.