User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C# section within the Software Development category of DaniWeb, a massive community of 374,011 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,725 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C# advertiser:
Views: 15911 | Replies: 2
Reply
Join Date: Apr 2004
Posts: 555
Reputation: Dark_Omen is an unknown quantity at this point 
Rep Power: 6
Solved Threads: 6
Dark_Omen Dark_Omen is offline Offline
Posting Pro

problem reading xml file in c#

  #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.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jul 2003
Location: Bamberg, Germany
Posts: 117
Reputation: Iron_Cross is an unknown quantity at this point 
Rep Power: 6
Solved Threads: 2
Iron_Cross's Avatar
Iron_Cross Iron_Cross is offline Offline
Junior Poster

Re: problem reading xml file in c#

  #2  
May 13th, 2005
try:
publicstatic Response Message(string doc)
{
     XmlTextReader textReader = new XmlTextReader(doc);
     XmlDocument xmlDoc = new XmlDocument(); 
     xmlDoc.Load(textReader); 
     return Response.Message(xmlDoc);
}
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  
Join Date: Apr 2004
Posts: 555
Reputation: Dark_Omen is an unknown quantity at this point 
Rep Power: 6
Solved Threads: 6
Dark_Omen Dark_Omen is offline Offline
Posting Pro

Re: problem reading xml file in c#

  #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  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb C# Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the C# Forum

All times are GMT -4. The time now is 10:59 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC