Last active
August 29, 2015 14:08
-
-
Save groovyghoul/c46e220395e7b9e62e5c to your computer and use it in GitHub Desktop.
Roll through Xml elements
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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