Trying to deserialize some xml snippits from a vendor into objects. The problem is that I\'m getting an invalid format on every empy element tag. I can deserialize the obj
The most uniform way to clean out these nodes appears to be to add a RegEx filter to the deserializer.
public static T Deserialize(string xml){ XmlSerializer xs = new XmlSerializer(typeof(T)); string cleanXml = Regex.Replace(xml, @"<[a-zA-Z].[^(><.)]+/>", new MatchEvaluator(RemoveText)); MemoryStream memoryStream = new MemoryStream((new UTF8Encoding()).GetBytes(cleanXml)); XmlTextWriter xmlTextWriter = new XmlTextWriter(memoryStream, Encoding.UTF8); return (T)xs.Deserialize(memoryStream); }
static string RemoveText(Match m) { return "";}