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

Started by
3 comments, last by Aidamina 18 years, 3 months ago
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]
-->My Site<--
Advertisement
At the risk of sounding dense, is there an actual problem?

Beginner in Game Development?  Read here. And read here.

 

I see a problem....

Your "<root>" element is unmatched because your final element is "</root2>"

The XML is malformed.
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);
}
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 outputError: 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]
-->My Site<--

This topic is closed to new replies.

Advertisement