• Advertisement
Sign in to follow this  

[SOLVED] System.Xml.LoadXml (c#)

This topic is 4501 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Solved: I made the compiler output the exe to a subfolder of the main project folder with the same name as the main project folder. For some reason VS 2003.NET glitches and when i add the Settings.xml from the subdirectory to the project it automatically creates an emty Settings.xml in the root of the project and adds that file. So instead of me editing the Settings.xml in the subdirectory i was editing the one in the root leaving the loaded Settings.xml empty. Sorrt for wasting your time people its just a glitch in VS 2003.NET Regards, Aidamina I wrote an app that loads an xml file for settings: piece of code of a method of an instanced class:
try 
{
        System.IO.TextReader tr = new System.IO.StreamReader("Settings.xml");
	string xmlcontent = tr.ReadToEnd();
				
	System.Xml.XmlDocument Settings = new System.Xml.XmlDocument();
	Settings.LoadXml(xmlcontent);
}
catch (System.Exception e)
{
	Console.WriteLine("Exception reported: {0}",e.Message);
}
Xml file:
<?xml version="1.0"?>
<root>
<Main>
<Configuration>
<UseForm>true</UseForm>
</Configuration>
</Main>
</root2>
[Edited by - Aidamina on December 30, 2005 8:05:44 AM]

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
You can also load an xml document using the .Load(string pathToFile) method.

try
{
System.Xml.XmlDocument Settings = new System.Xml.XmlDocument();
Settings.Load("Settings.xml");
}
catch (System.Exception e)
{
Console.WriteLine("Exception reported: {0}",e.Message);
}

Share this post


Link to post
Share on other sites
I'm sorry for the bad post
the </root2> was just a typo and wasnt causing a problem

The program doesnt load the xml correctly:
Error:
Exception reported: The root element is missing.

The code provided by Anonymous poster generates the same error.


When i run it through the xml-schema validator of www.w3c.org. It gives this output:


Low-level XML well-formedness and/or validity processing output

Error: Document ends too soon
in unnamed entity at line 1 char 42 of Settings.xml


[Edited by - Aidamina on December 30, 2005 7:39:25 AM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement