views:

92

answers:

1

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

+1  A: 

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));
Martin Honnen
Thanks Martin. I've something similar now, the problem is the transform files are fairly large around 500K-1M. When multiple XML documents are processed concurrently, say around 10 XMLs, the memory spikes to 1.5G+ and processor on a dual core runs between 98-99% usage. With 1 document, the processor usage is stil 98-99% but the memory usage is around 300MMachine specs:2x2dual core Intel Xeon 1.6GHz4G Windows 2008 x64
G33kKahuna
Okay, leanred something new. Used the same code as above and used another overload .Load(Type) instead of .Load(String). This shot down the resource utlization to 1/10th ... thanks for you assistance Martin.
G33kKahuna