Skip to content

Instantly share code, notes, and snippets.

@groovyghoul
Last active August 29, 2015 14:08
Show Gist options
  • Save groovyghoul/c46e220395e7b9e62e5c to your computer and use it in GitHub Desktop.
Save groovyghoul/c46e220395e7b9e62e5c to your computer and use it in GitHub Desktop.
Roll through Xml elements
Add `System.Runtime.Serialization` to the using clauses
public static object Deserialize(string path)
{
using (var sr = new FileStream(path, FileMode.Open))
{
creditBureau p = null;
XmlDictionaryReader reader = XmlDictionaryReader.CreateTextReader(sr, new XmlDictionaryReaderQuotas());
var serializer = new DataContractSerializer(typeof(creditBureau));
while (reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.Element:
if (serializer.IsStartObject(reader))
{
Console.WriteLine(@"Found the element");
p = (creditBureau)serializer.ReadObject(reader);
//Console.WriteLine("{0} {1} id:{2}",
// p.Slash.ToString(), p.Summon.ToString());
}
Console.WriteLine(reader.Name);
break;
}
}
return p;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment