# Anonymous methods, factory methods, threading, and XML input

I have an application which retrieves data from a (potentially) very large XML file. A combination of XMLReader and XDocument seemed to be the only way I could manage the entire thing the way I wanted. It works, and it does so fairly quickly and efficiently. But I have a few review questions.

• Is this combination of XMLReader and XDocument the right way to go? Nothing I read about managing XML documents suggested it, but it was the only option I could come up with since XDocument can't load entire sections, so XMLReader is needed as well.
• Activator.CreateInstance is not something I truly understand and it was just the last in a line of options I tried there. It seems to do what I want, but is there some issues I should know about?
• The reason for the distinction between factory methods and Activator.CreatInstance is because the factory methods ifs contain classes which may return subclasses, the activator else doesn't. Is there a better way of handling this?

public static void Parse(World world, string path)
{
isFinished = false;

World = world;
Path = path;

{
continue;
{
{
continue;
break;
bool knownSection = true;
{
case "regions":
break;
case "underground_regions":
break;
case "sites":
break;
//Other cases culled for brevity
default:
Program.Log(LogType.Error, "Unknown XML Section: " + XReader.Name);
knownSection = false;
break;
}
if (knownSection)
}
break;
}
}
isFinished = true;
OnFinished();
}

private static void LoadSection<T>(Dictionary<int, T> WorldList) where T : XMLObject
{
{
continue;
continue;
break;
else
Program.Log(LogType.Error, "Unknown part of section xml/n" + XReader.Name);
}
}

private static void LoadItem<T>(Dictionary<int, T> WorldList) where T : XMLObject
{
try
{
if (typeof(T)  == typeof(HistoricalEvent))
{
HistoricalEvent evt = HistoricalEvent.Create(xdoc, World);
}
else if (typeof(T) == typeof(HistoricalEventCollection))
{
HistoricalEventCollection evtcol = HistoricalEventCollection.Create(xdoc, World);
}
else
{
T WorldObject = (T)Activator.CreateInstance(typeof(T), new object[] { xdoc, World });
}

}
catch (Exception e )
{
Program.Log(LogType.Error, "Error reading XML item\n" + e.Message);
}

}


using (var streamReader = new StreamReader(Path, Encoding.GetEncoding("ISO-8859-9"))

I don't like the variable name XReader. I don't see the declaration, but it should be a local variable, and named xReader. If it is a property, I would rethink the name. Same with World and Path (I"m assuming these are class properties). Why are you saving those variables in Properties any ways? Are they really needed anywhere else?