problem reading xml file in c#

Please support our C# advertiser: $4.95 a Month - ASP.NET Web Hosting – Click Here!
Reply

Join Date: Apr 2004
Posts: 573
Reputation: Dark_Omen is an unknown quantity at this point 
Solved Threads: 6
Dark_Omen Dark_Omen is offline Offline
Posting Pro

problem reading xml file in c#

 
0
  #1
May 6th, 2005
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.
Reply With Quote Quick reply to this message  
Join Date: Jul 2003
Posts: 117
Reputation: Iron_Cross is an unknown quantity at this point 
Solved Threads: 2
Iron_Cross's Avatar
Iron_Cross Iron_Cross is offline Offline
Junior Poster

Re: problem reading xml file in c#

 
0
  #2
May 13th, 2005
try:
  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.
elitehackers.info
Today's Penny-Arcade!
Pain is weakness leaving the body!
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 573
Reputation: Dark_Omen is an unknown quantity at this point 
Solved Threads: 6
Dark_Omen Dark_Omen is offline Offline
Posting Pro

Re: problem reading xml file in c#

 
0
  #3
May 13th, 2005
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC