Question

Is there a way to deserialize a XML stream using XmlSerializer by applying a custom transform defined in a XSLT?

Was it helpful?

Solution

I don't think there is a single API call that would allow that but you could certainly implement that with a few lines along the following approach:

XslCompiledTransform proc = new XslCompiledTransform();
proc.Load("sheet.xsl");

XmlDocument tempResult = new XmlDocument();
using (XmlWriter xw = tempResult.CreateNavigator().AppendChild())
{
  proc.Transform("input.xml", null, xw);
  xw.Close();
}

XmlSerializer ser = new XmlSerializer(typeof(Foo));
Foo foo = (Foo)ser.Deserialize(new XmlNodeReader(tempResult));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top