Click here to Skip to main content
15,897,334 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XmlReader reader = cmd.ExecuteXmlReader();
con.Close();
XmlDocument doc = new XmlDocument();
doc.Load(reader);//at this line im getting error

and my xmlfile is

XML
<ID>76</ID>
<Name>ushaChaitu</Name>
<City>2</City>
<EmailID>UshaChaitu@Kp.com</EmailID>


there is no root element then why im getting this error when im loading this xmlfile
Posted
Comments
Sanket Saxena 9-May-14 3:20am    
As we don't know how your are creating the xml file via code so cant detect the issue. See my solution might be they help you :)

you need to have a root not to be a valid XML Document. Do as below

C#
string xmlContent = File.ReadAllText("yourxmlFilePath.xml");
XDocument x= XDocument.Parse("<root>"+xml+"</root>");
 
Share this answer
 
Comments
Usha Sanjee 9-May-14 4:05am    
thank u i got it.
Seems your xml file is not well formed like where is the
XML
<?xml version="1.0" encoding="utf-8"?> 
header.

Also refer the below link:
This-document-already-has-a-DocumentElement
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900