Connecting Tech Pros Worldwide Help | Site Map

Data at the root level is invalid. Line 1, position 1'

Newbie
 
Join Date: Aug 2009
Posts: 3
#1: Aug 25 '09
xml file is

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <Books>
  3.     <Book id="1">
  4.         <Author>Mark</Author>
  5.         <Publisher>Sams</Publisher>
  6.     </Book>
  7. </Books>
Code Behind is

Expand|Select|Wrap|Line Numbers
  1. string myXmlString="D:\books.xml";
  2.         XmlDocument docxml = new XmlDocument();
  3.         docxml.LoadXml(myXmlString);
  4.         XmlNodeList xmlist = docxml.SelectNodes("Books/Book");
  5.         foreach (XmlNode xn in xmlist)
  6.         {
  7.             Uname.Text = xn["Author"].InnerText;
  8.         }
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,635
#2: Aug 25 '09

re: Data at the root level is invalid. Line 1, position 1'


the XML code posted is correct. you may check the LoadXml() function, whether it accepts the XML Prolog. other than that you may have a BOM (Byte Order Mark) at the beginning of your file, which can cause problems.
Newbie
 
Join Date: Aug 2009
Posts: 3
#3: Aug 25 '09

re: Data at the root level is invalid. Line 1, position 1'


I did not get.What is BOM?
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,635
#4: Aug 25 '09

re: Data at the root level is invalid. Line 1, position 1'


ask Mr. Wikipedia


.........
Newbie
 
Join Date: Aug 2009
Posts: 3
#5: Aug 25 '09

re: Data at the root level is invalid. Line 1, position 1'


Leave BOM....
You know what I m trying to do....
Do you have any other code to solve this...I need it help plz
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,635
#6: Aug 25 '09

re: Data at the root level is invalid. Line 1, position 1'


Quote:

Originally Posted by vinaykumarrajpoot View Post

You know what I m trying to do...

do I? well, I can make sense of the code…

Quote:

Originally Posted by vinaykumarrajpoot View Post

Do you have any other code to solve this...I need it help plz

nope, don’t know anything about C# ( C#? ;)
Newbie
 
Join Date: Sep 2009
Posts: 1
#7: Sep 18 '09

re: Data at the root level is invalid. Line 1, position 1'


try this:
docxml.Load(myXmlString);
Reply