tags:

views:

62

answers:

1

I'm trying to write an XmlDocument from an instance of a class to pass to BizTalk (2006 R2, if it matters). I'm implementing IXmlSerializable because I believe it'll give me the most flexibility (this object won't necessarilly always be written to an XmlDocument and passed to BizTalk).

So, I have implemented IXmlSerializable, and now I'd like to use the Write() method to create the actual XmlDocument instance to be passed to BizTalk. Something like:

XmlDocument xDoc = new XmlDocument();
xDoc.LoadXml(XmlWriter.Create(this.Write());

Obviously the above doesn't work: I'm pretty sure it doesn't even compile... but that's the functionality I'm looking for.

Does anyone have a canned solution for this, or a place I can go to look for examples or a tutorial?

+2  A: 

IXmlSerializable is implemented when you would like to add custom serialization logic, this means that you need to use the XmlSerializer to have it call your implemented logic.

XmlSerializer ser = new XmlSerializer(this.GetType());
ser.Serialize(stream, this);

stream could be XmlWriter, TextWriter, Stream which you can then load into XmlDocument if you wish.

Here is some more info

IXmlSerializable Interface

Stan R.
Ah! That makes much more sense. I don't know why I completely forgot about XmlSerializer...
AllenG