Infopath Form Serialization and Schema Names

If you are working with SharePoint 2007 workflows, then you've probably had a need to serialize and deserialize InfoPath forms xml data based on the instructions here: How to: Access Association and Initiation Form Data in a Workflow. I've found that running the xsd.exe on the myschema.xsd exported in the source files of an Infopath form results in a root class defined as follows:

[System.Xml.Serialization.XmlRootAttribute(Namespace="", IsNullable=false)]
public partial class myFields {

That myFields class name irks me a bit. The instructions referenced in the HowTo article above includes the following text to address this:

Specifying a unique name for the form fields collection, rather than using the default name of myfields, helps ensure the class that is generated from the form schema file also has a unique name. This is especially important when you are programming a workflow that uses multiple forms.

However, you might not have control over the form design if you are not creating the forms yourself. Rather than editing the code in the generated scheme, you can alter the name of the myFields class inside the InfoPath form before generating your concrete class with xsd.exe.

[System.Xml.Serialization.XmlRootAttribute(Namespace="", IsNullable=false,ElementName="myFields" )]
    public partial class InitWorkflow {

Specifying the ElementName in the XmlRootAttribute maintains compatibility with the xml document while allowing for a more logical class name. The price paid lies in the alteration of a tool-generated class. If xsd.exe is run against the myschema.xsd source file, then this manual change will need to be re-applied.