private static Projects Deserialise(XmlDocument xmlDoc) { var nodeReader = new XmlNodeReader(xmlDoc); nodeReader.ReadToDescendant("Projects"); var result = Serialiser.Deserialize(nodeReader); return((Projects)result); }
static void Main(string[] args) { string fileName = "c:\path\to\file\test.xml"; var xmlDoc = new XmlDocument(); xmlDoc.Load(File.OpenRead(fileName)); XmlNodeList nodeList = xmlDoc.GetElementsByTagName("port"); XmlNodeReader nodeReader; foreach (var node in nodeList) { using (nodeReader = new XmlNodeReader((XmlNode)node)) { if (nodeReader.ReadToDescendant("script")) { Console.WriteLine("Found script tag"); } } } Console.ReadKey(); }
public static T Deserialize <T>(string path, string section = "") { try { var serializer = new XmlSerializer(typeof(T), new XmlRootAttribute(section)); var doc = new XmlDocument(); doc.Load(path); using (var reader = new XmlNodeReader(doc)) { if (section != string.Empty) { reader.ReadToDescendant(section); } var temp = (T)serializer.Deserialize(reader); reader.Close(); return(temp); } } catch (Exception e) { throw; } }