I've been trying to find an easy way to write XML using the XmlReader/XmlWriter. I don't really like using the interface "IXmlSerializable", but I've got no choice for some of my dataclass.
Anyway, what I want to do is quite simple:
private MyClass myObject;
public void WriteXml(XmlWriter writer)
{
writer.WriteObject(myObject); // <-- this method doesn't exists
}
So, I found 2 work around:
- Write my own routine to write my object manually. Quite ridiculous since .Net already does it.
- Create a new serializer using a StringWriter and use the WriteValue(string) method.
I haven't tested the second yet but I think it will probably work (not sure because of the ReadValue result).
Then my question is: Am I missing something important or is it the only way? Or is there a better way to handle that?
Thanks.