DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/)
-   C# (http://www.daniweb.com/forums/forum61.html)
-   -   problem reading xml file in c# (http://www.daniweb.com/forums/thread23144.html)

Dark_Omen May 6th, 2005 11:19 am
problem reading xml file in c#
 
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.

Iron_Cross May 13th, 2005 12:24 pm
Re: problem reading xml file in c#
 
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.

Dark_Omen May 13th, 2005 3:38 pm
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.


All times are GMT -4. The time now is 2:17 am.

Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC