943,929 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 24136
  • C# RSS
May 6th, 2005
0

problem reading xml file in c#

Expand Post »
Hello,

I am trying to read this xml file. But whenever I get to the load part of it, it gives me this error: "The data at the root level is invalid. Line 1, position 1"
This is the code I am working with:
publicstatic Response Message(string doc)
{
		 StringReader reader = new StringReader(doc);
		 XmlTextReader textReader = new XmlTextReader(reader);
		 XmlDocument xmlDoc = new XmlDocument();
		 xmlDoc.Load(textReader); //gets stuck here
return Response.Message(xmlDoc);
}

doc is the filepath of the xml document.

If anybody has any idea on how to solve this problem that would be great.
Similar Threads
Reputation Points: 23
Solved Threads: 6
Posting Pro
Dark_Omen is offline Offline
573 posts
since Apr 2004
May 13th, 2005
0

Re: problem reading xml file in c#

try:
C# Syntax (Toggle Plain Text)
  1. publicstatic Response Message(string doc)
  2. {
  3. XmlTextReader textReader = new XmlTextReader(doc);
  4. XmlDocument xmlDoc = new XmlDocument();
  5. xmlDoc.Load(textReader);
  6. return Response.Message(xmlDoc);
  7. }
If that doesn't work, post the xml document you're trying to read.
Reputation Points: 46
Solved Threads: 2
Junior Poster
Iron_Cross is offline Offline
117 posts
since Jul 2003
May 13th, 2005
0

Re: problem reading xml file in c#

Yeah I fixed tehe problem. The problem was that it had the encoding and version in the xml file, when really I was trying to take the node in a file and put it into an existing xml file, and it was getting messed up because it saw that. So I took it out and it worked.

Thanks for the help though.
Reputation Points: 23
Solved Threads: 6
Posting Pro
Dark_Omen is offline Offline
573 posts
since Apr 2004
Oct 26th, 2010
0
Re: problem reading xml file in c#
Read data from XML file in C Sharp

To read data from XML file we have to assign XML file to data set using ReadXml() function of dataset.

please check this link related to this topic

http://www.mindstick.com/Articles/85...-d83b5fd0adf2/
Last edited by bbauraj; Oct 26th, 2010 at 7:05 am.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
bbauraj is offline Offline
6 posts
since May 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: Problem with StreamWriter
Next Thread in C# Forum Timeline: Problem with Listview sorter





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC