<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://www.infopathdev.com:443/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>General</title><link>https://www.infopathdev.com:443/forums/41.aspx</link><description>If you're not sure where to ask your question, ask it here. If necessary, our moderators will make sure it gets classified in the correct board.</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP3 (Build: 31118.962)</generator><item><title>Re: Creating InfoPath XML from C#</title><link>https://www.infopathdev.com:443/forums/thread/65049.aspx</link><pubDate>Thu, 10 Mar 2011 05:38:29 GMT</pubDate><guid isPermaLink="false">033a2e2d-04e2-4a9d-be01-a4634161eefd:65049</guid><dc:creator>Lala Waghmode</dc:creator><slash:comments>0</slash:comments><comments>https://www.infopathdev.com:443/forums/thread/65049.aspx</comments><wfw:commentRss>https://www.infopathdev.com:443/forums/commentrss.aspx?SectionID=41&amp;PostID=65049</wfw:commentRss><description>&lt;p&gt;&amp;nbsp;Hello Matt.&lt;/p&gt;&lt;p&gt;I read your blogs and came to know,you have a answer for my query.&lt;/p&gt;&lt;p&gt;please give me a code and exact references for my assignment.&lt;/p&gt;&lt;p&gt;&lt;b&gt;I have to convert any infopath template into XML &lt;/b&gt;for platform interoperability.&lt;/p&gt;&lt;p&gt;I am waiting...&lt;/p&gt;&lt;p&gt;Best Regards,&lt;/p&gt;&lt;p&gt;Lala &lt;br /&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description></item><item><title>Re: Creating InfoPath XML from C#</title><link>https://www.infopathdev.com:443/forums/thread/22008.aspx</link><pubDate>Thu, 26 Jul 2007 13:01:10 GMT</pubDate><guid isPermaLink="false">033a2e2d-04e2-4a9d-be01-a4634161eefd:22008</guid><dc:creator>victorv</dc:creator><slash:comments>0</slash:comments><comments>https://www.infopathdev.com:443/forums/thread/22008.aspx</comments><wfw:commentRss>https://www.infopathdev.com:443/forums/commentrss.aspx?SectionID=41&amp;PostID=22008</wfw:commentRss><description>&lt;p&gt;An update to my Serialization problem, because I got it to work and now have a little time to describe the solution.&lt;/p&gt;&lt;p&gt;CASE: I need to read and write InfoPath forms in .NET 1.1.&lt;br /&gt;DIRECTION: Using XML Serialization.&lt;br /&gt;FACT: .NET 1.1 XML serialization does not respect the sequence specification in the XSD from the InfoPath template. In normal words: reading (de-serializing)&amp;nbsp;XML from a form is fine, but writing to XML (serializing) sometimes mixes up the order of fields in the output which makes it unreadable again without exceptions.&lt;br /&gt;FACT: .NET 1.1 handles &amp;#39;empty&amp;#39; fields that have been mapped to value types like &amp;#39;int&amp;#39; badly (formatexception while de-serializing).&lt;/p&gt;&lt;p&gt;I started using XSDObjectGen 1.4.2.1 instead of XSD.exe to generate the C# classes for serialization. These are quite different from the classes generated by XSD.exe.&lt;br /&gt;But these XSDObjectGen generated C# classes are working perfectly with .NET 1.1 XML Serialization! Both reading (deserialization) and writing (serialization) of XML form data worked like a charm. &lt;br /&gt;I can now create InfoPath forms from code!&amp;nbsp;Thanks to&amp;nbsp;XSDObjectGen creating data instances is a breeze in comparison to XSD.exe generated classes.&lt;/p&gt;&lt;p&gt;The only snag is an XML form data contains a PREPROCESSING instruction which is be written by the XML Serialization process. I wrote a custom XmlTextWriter to solve this problem. There is some code below.&lt;/p&gt;&lt;p&gt;One other important thing which is about value type fields. If you have an integer field in your InfoPath form and you don&amp;#39;t enter a value in the form, the field in form&amp;#39;s XML will be empty. While de-serializing, this will be a problem because the serialization engine will try to map the empty value to an integer field in the C# class -&amp;gt; FormatException.&lt;br /&gt;I chose to make allmost all fields in my InfoPath template a STRING. Result is that I don&amp;#39;t have FormatExceptions, but do need to check or convert&amp;nbsp;the fields in my code to apopriate types.&lt;/p&gt;&lt;p&gt;This is some example C# code to write an (XSDObjectGen) class instance of an InfoPath form to a stream (for example a FileStream) to produce an XML file, which represents an InfoPath form file.&lt;/p&gt;&lt;font size="2"&gt;&lt;p&gt;XmlTextAndProcessingInstructionsWriter writer =&amp;nbsp;&lt;font color="#0000ff" size="2"&gt;new&lt;/font&gt;&lt;font size="2"&gt; XmlTextAndProcessingInstructionsWriter(writeStream, Encoding.UTF8);&lt;p&gt;writer.ProcessingInstructions = GetFormProcessingInstructions(); &lt;br /&gt;// GetFormProcessingInstructions() = CUSTOM function to create processing instruction text,&amp;nbsp;like:&lt;br /&gt;// &amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot;?&amp;gt;&lt;br /&gt;// &amp;lt;?mso-infoPathSolution solutionVersion=&amp;quot;1.0.0.67&amp;quot; productVersion=&amp;quot;11.0.6357&amp;quot; PIVersion=&amp;quot;1.0.0.0&amp;quot; &lt;br /&gt;//&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; href=&amp;quot;&lt;a&gt;file:///C:\SCC\Macaw.BeoordelingsProces\Doc.InfoPathTemplates\PDP.xsn&lt;/a&gt;&amp;quot; name=&amp;quot;urn:schemas-microsoft-com:office:infopath:PDP:-myXSD-2006-02-25T22-08-56&amp;quot; ?&amp;gt;&lt;br /&gt;//&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;?mso-application progid=&amp;quot;InfoPath.Document&amp;quot;?&amp;gt;&lt;/p&gt;&lt;p&gt;&lt;font color="#008000" size="2"&gt;// Prepare namespaces for the output serialization&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;new&lt;/font&gt;&lt;font size="2"&gt; XmlTextAndProcessingInstructionsWriter(writeStream, Encoding.UTF8);&lt;p&gt;writer.ProcessingInstructions = GetFormProcessingInstructions(); &lt;br /&gt;// GetFormProcessingInstructions() = CUSTOM function to create processing instruction text,&amp;nbsp;like:&lt;br /&gt;// &amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot;?&amp;gt;&lt;br /&gt;// &amp;lt;?mso-infoPathSolution solutionVersion=&amp;quot;1.0.0.67&amp;quot; productVersion=&amp;quot;11.0.6357&amp;quot; PIVersion=&amp;quot;1.0.0.0&amp;quot; &lt;br /&gt;//&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; href=&amp;quot;&lt;a&gt;file:///C:\SCC\Macaw.BeoordelingsProces\Doc.InfoPathTemplates\PDP.xsn&lt;/a&gt;&amp;quot; name=&amp;quot;urn:schemas-microsoft-com:office:infopath:PDP:-myXSD-2006-02-25T22-08-56&amp;quot; ?&amp;gt;&lt;br /&gt;//&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;?mso-application progid=&amp;quot;InfoPath.Document&amp;quot;?&amp;gt;&lt;/p&gt;&lt;p&gt;&lt;font color="#008000" size="2"&gt;// Prepare namespaces for the output serialization&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;font color="#008000" size="2"&gt;// Prepare namespaces for the output serialization&lt;/font&gt;&lt;font size="2"&gt;&lt;p&gt;XmlSerializerNamespaces ns = &lt;font color="#0000ff" size="2"&gt;new&lt;/font&gt;&lt;font size="2"&gt; XmlSerializerNamespaces();&lt;p&gt;&lt;font color="#008000" size="2"&gt;// Add xsi standard to the namespace table&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;new&lt;/font&gt;&lt;font size="2"&gt; XmlSerializerNamespaces();&lt;p&gt;&lt;font color="#008000" size="2"&gt;// Add xsi standard to the namespace table&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;font color="#008000" size="2"&gt;// Add xsi standard to the namespace table&lt;/font&gt;&lt;font size="2"&gt;&lt;p&gt;ns.Add(&amp;quot;xsi&amp;quot;, &amp;quot;http://www.w3.org/2001/XMLSchema-instance&amp;quot;);&lt;/p&gt;&lt;p&gt;&lt;font color="#008000" size="2"&gt;// Use Reflection to retrieve the namespace from the&amp;nbsp;FORM type&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;font color="#008000" size="2"&gt;// Use Reflection to retrieve the namespace from the&amp;nbsp;FORM type&lt;/font&gt;&lt;font size="2"&gt;&lt;p&gt;Type FormType = &lt;font color="#0000ff" size="2"&gt;typeof&lt;/font&gt;&lt;font size="2"&gt;(FORM);&amp;nbsp; // FORM is an XSDObjectGen generated class&lt;p&gt;XmlRootAttribute[] xmlRootAttrs = (XmlRootAttribute[])FormType.GetCustomAttributes(&lt;font color="#0000ff" size="2"&gt;typeof&lt;/font&gt;&lt;font size="2"&gt;(System.Xml.Serialization.XmlRootAttribute), &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;false&lt;/font&gt;&lt;font size="2"&gt;);&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;if&lt;/font&gt;&lt;font size="2"&gt; (xmlRootAttrs.Length &amp;gt; 0)&lt;p&gt;{&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp; ns.Add(&amp;quot;my&amp;quot;, xmlRootAttrs[0].Namespace);&lt;/p&gt;&lt;p&gt;}&lt;/p&gt;&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;typeof&lt;/font&gt;&lt;font size="2"&gt;(FORM);&amp;nbsp; // FORM is an XSDObjectGen generated class&lt;p&gt;XmlRootAttribute[] xmlRootAttrs = (XmlRootAttribute[])FormType.GetCustomAttributes(&lt;font color="#0000ff" size="2"&gt;typeof&lt;/font&gt;&lt;font size="2"&gt;(System.Xml.Serialization.XmlRootAttribute), &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;false&lt;/font&gt;&lt;font size="2"&gt;);&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;if&lt;/font&gt;&lt;font size="2"&gt; (xmlRootAttrs.Length &amp;gt; 0)&lt;p&gt;{&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp; ns.Add(&amp;quot;my&amp;quot;, xmlRootAttrs[0].Namespace);&lt;/p&gt;&lt;p&gt;}&lt;/p&gt;&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;typeof&lt;/font&gt;&lt;font size="2"&gt;(System.Xml.Serialization.XmlRootAttribute), &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;false&lt;/font&gt;&lt;font size="2"&gt;);&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;if&lt;/font&gt;&lt;font size="2"&gt; (xmlRootAttrs.Length &amp;gt; 0)&lt;p&gt;{&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp; ns.Add(&amp;quot;my&amp;quot;, xmlRootAttrs[0].Namespace);&lt;/p&gt;&lt;p&gt;}&lt;/p&gt;&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;if&lt;/font&gt;&lt;font size="2"&gt; (xmlRootAttrs.Length &amp;gt; 0)&lt;p&gt;{&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp; ns.Add(&amp;quot;my&amp;quot;, xmlRootAttrs[0].Namespace);&lt;/p&gt;&lt;p&gt;}&lt;/p&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;p&gt;XmlSerializer ser = &lt;font color="#0000ff" size="2"&gt;new&lt;/font&gt;&lt;font size="2"&gt; XmlSerializer(&lt;font color="#0000ff"&gt;typeof&lt;/font&gt;&lt;font size="2"&gt;(FORM)&lt;/font&gt;);&lt;p&gt;ser.Serialize(writer, formdata, ns);&amp;nbsp;&amp;nbsp; // formdata is an instance of the XSDObjectGen generated class&lt;/p&gt;&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;new&lt;/font&gt;&lt;font size="2"&gt; XmlSerializer(&lt;font color="#0000ff"&gt;typeof&lt;/font&gt;&lt;font size="2"&gt;(FORM)&lt;/font&gt;);&lt;p&gt;ser.Serialize(writer, formdata, ns);&amp;nbsp;&amp;nbsp; // formdata is an instance of the XSDObjectGen generated class&lt;/p&gt;&lt;/font&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;font color="#808080" size="2"&gt;&lt;p&gt;///&lt;font color="#008000" size="2"&gt; &lt;/font&gt;&lt;font color="#808080" size="2"&gt;&amp;lt;summary&amp;gt;&lt;p&gt;///&lt;font color="#008000" size="2"&gt; The XmlTextAndProcessingInstructionsWriter is derived from XmlTextWriter and &lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;font color="#008000" size="2"&gt; &lt;/font&gt;&lt;font color="#808080" size="2"&gt;&amp;lt;summary&amp;gt;&lt;p&gt;///&lt;font color="#008000" size="2"&gt; The XmlTextAndProcessingInstructionsWriter is derived from XmlTextWriter and &lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;font color="#008000" size="2"&gt; The XmlTextAndProcessingInstructionsWriter is derived from XmlTextWriter and &lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;p&gt;///&lt;font color="#008000" size="2"&gt; writes out the attached xml processing instructions when writing the xml.&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;font color="#008000" size="2"&gt; writes out the attached xml processing instructions when writing the xml.&lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;p&gt;///&lt;font color="#008000" size="2"&gt; Attach the processing instructions collection to the writer before writing&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;font color="#008000" size="2"&gt; Attach the processing instructions collection to the writer before writing&lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;p&gt;///&lt;font color="#008000" size="2"&gt; the xml document. The writer will output the processing instructions at the correct&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;font color="#008000" size="2"&gt; the xml document. The writer will output the processing instructions at the correct&lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;p&gt;///&lt;font color="#008000" size="2"&gt; location in the xml file.&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;font color="#008000" size="2"&gt; location in the xml file.&lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;p&gt;///&lt;font color="#008000" size="2"&gt; &lt;/font&gt;&lt;font color="#808080" size="2"&gt;&amp;lt;/summary&amp;gt;&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;font color="#008000" size="2"&gt; &lt;/font&gt;&lt;font color="#808080" size="2"&gt;&amp;lt;/summary&amp;gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;p&gt;public&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;class&lt;/font&gt;&lt;font size="2"&gt; XmlTextAndProcessingInstructionsWriter : XmlTextWriter&lt;p&gt;{&lt;/p&gt;&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;class&lt;/font&gt;&lt;font size="2"&gt; XmlTextAndProcessingInstructionsWriter : XmlTextWriter&lt;p&gt;{&lt;/p&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;p&gt;private&lt;font size="2"&gt; NameValueCollection _processingInstructions = &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;new&lt;/font&gt;&lt;font size="2"&gt; NameValueCollection();&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;font size="2"&gt; NameValueCollection _processingInstructions = &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;new&lt;/font&gt;&lt;font size="2"&gt; NameValueCollection();&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;p&gt;public&lt;font size="2"&gt; XmlTextAndProcessingInstructionsWriter(TextWriter w) : &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;base&lt;/font&gt;&lt;font size="2"&gt;(w)&lt;p&gt;{&lt;/p&gt;&lt;p&gt;Init();&lt;/p&gt;&lt;p&gt;}&lt;/p&gt;&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;font size="2"&gt; XmlTextAndProcessingInstructionsWriter(TextWriter w) : &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;base&lt;/font&gt;&lt;font size="2"&gt;(w)&lt;p&gt;{&lt;/p&gt;&lt;p&gt;Init();&lt;/p&gt;&lt;p&gt;}&lt;/p&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;p&gt;public&lt;font size="2"&gt; XmlTextAndProcessingInstructionsWriter(&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;string&lt;/font&gt;&lt;font size="2"&gt; filename, Encoding encoding) : &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;base&lt;/font&gt;&lt;font size="2"&gt;(filename, encoding)&lt;p&gt;{&lt;/p&gt;&lt;p&gt;Init();&lt;/p&gt;&lt;p&gt;}&lt;/p&gt;&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;font size="2"&gt; XmlTextAndProcessingInstructionsWriter(&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;string&lt;/font&gt;&lt;font size="2"&gt; filename, Encoding encoding) : &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;base&lt;/font&gt;&lt;font size="2"&gt;(filename, encoding)&lt;p&gt;{&lt;/p&gt;&lt;p&gt;Init();&lt;/p&gt;&lt;p&gt;}&lt;/p&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;p&gt;public&lt;font size="2"&gt; XmlTextAndProcessingInstructionsWriter(Stream w, Encoding encoding) : &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;base&lt;/font&gt;&lt;font size="2"&gt;(w, encoding)&lt;p&gt;{&lt;/p&gt;&lt;p&gt;Init();&lt;/p&gt;&lt;p&gt;}&lt;/p&gt;&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;font size="2"&gt; XmlTextAndProcessingInstructionsWriter(Stream w, Encoding encoding) : &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;base&lt;/font&gt;&lt;font size="2"&gt;(w, encoding)&lt;p&gt;{&lt;/p&gt;&lt;p&gt;Init();&lt;/p&gt;&lt;p&gt;}&lt;/p&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;p&gt;private&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;void&lt;/font&gt;&lt;font size="2"&gt; Init()&lt;p&gt;{&lt;/p&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;this&lt;/font&gt;&lt;font size="2"&gt;.Formatting = Formatting.Indented;&lt;p&gt;}&lt;/p&gt;&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;void&lt;/font&gt;&lt;font size="2"&gt; Init()&lt;p&gt;{&lt;/p&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;this&lt;/font&gt;&lt;font size="2"&gt;.Formatting = Formatting.Indented;&lt;p&gt;}&lt;/p&gt;&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;this&lt;/font&gt;&lt;font size="2"&gt;.Formatting = Formatting.Indented;&lt;p&gt;}&lt;/p&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;p&gt;public&lt;font size="2"&gt; NameValueCollection ProcessingInstructions&lt;p&gt;{&lt;/p&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;set&lt;/font&gt;&lt;font size="2"&gt; { &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;this&lt;/font&gt;&lt;font size="2"&gt;._processingInstructions = &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;value&lt;/font&gt;&lt;font size="2"&gt;; }&lt;p&gt;}&lt;/p&gt;&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;font size="2"&gt; NameValueCollection ProcessingInstructions&lt;p&gt;{&lt;/p&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;set&lt;/font&gt;&lt;font size="2"&gt; { &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;this&lt;/font&gt;&lt;font size="2"&gt;._processingInstructions = &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;value&lt;/font&gt;&lt;font size="2"&gt;; }&lt;p&gt;}&lt;/p&gt;&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;set&lt;/font&gt;&lt;font size="2"&gt; { &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;this&lt;/font&gt;&lt;font size="2"&gt;._processingInstructions = &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;value&lt;/font&gt;&lt;font size="2"&gt;; }&lt;p&gt;}&lt;/p&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;p&gt;public&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;override&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;void&lt;/font&gt;&lt;font size="2"&gt; WriteStartDocument()&lt;p&gt;{&lt;/p&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;base&lt;/font&gt;&lt;font size="2"&gt;.WriteStartDocument();&lt;p&gt;WriteProcessingInstructions();&lt;/p&gt;&lt;p&gt;}&lt;/p&gt;&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;override&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;void&lt;/font&gt;&lt;font size="2"&gt; WriteStartDocument()&lt;p&gt;{&lt;/p&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;base&lt;/font&gt;&lt;font size="2"&gt;.WriteStartDocument();&lt;p&gt;WriteProcessingInstructions();&lt;/p&gt;&lt;p&gt;}&lt;/p&gt;&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;base&lt;/font&gt;&lt;font size="2"&gt;.WriteStartDocument();&lt;p&gt;WriteProcessingInstructions();&lt;/p&gt;&lt;p&gt;}&lt;/p&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;p&gt;public&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;override&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;void&lt;/font&gt;&lt;font size="2"&gt; WriteStartDocument(&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;bool&lt;/font&gt;&lt;font size="2"&gt; standalone)&lt;p&gt;{&lt;/p&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;base&lt;/font&gt;&lt;font size="2"&gt;.WriteStartDocument(standalone);&lt;p&gt;WriteProcessingInstructions();&lt;/p&gt;&lt;p&gt;}&lt;/p&gt;&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;override&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;void&lt;/font&gt;&lt;font size="2"&gt; WriteStartDocument(&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;bool&lt;/font&gt;&lt;font size="2"&gt; standalone)&lt;p&gt;{&lt;/p&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;base&lt;/font&gt;&lt;font size="2"&gt;.WriteStartDocument(standalone);&lt;p&gt;WriteProcessingInstructions();&lt;/p&gt;&lt;p&gt;}&lt;/p&gt;&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;base&lt;/font&gt;&lt;font size="2"&gt;.WriteStartDocument(standalone);&lt;p&gt;WriteProcessingInstructions();&lt;/p&gt;&lt;p&gt;}&lt;/p&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;p&gt;private&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;void&lt;/font&gt;&lt;font size="2"&gt; WriteProcessingInstructions()&lt;p&gt;{&lt;/p&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;if&lt;/font&gt;&lt;font size="2"&gt; (&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;this&lt;/font&gt;&lt;font size="2"&gt;._processingInstructions != &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;null&lt;/font&gt;&lt;font size="2"&gt;)&lt;p&gt;{&lt;/p&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;foreach&lt;/font&gt;&lt;font size="2"&gt;(&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;string&lt;/font&gt;&lt;font size="2"&gt; key &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;in&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;this&lt;/font&gt;&lt;font size="2"&gt;._processingInstructions.AllKeys)&lt;p&gt;{&lt;/p&gt;&lt;p&gt;WriteProcessingInstruction(key, &lt;font color="#0000ff" size="2"&gt;this&lt;/font&gt;&lt;font size="2"&gt;._processingInstructions[key]);&lt;p&gt;}&lt;/p&gt;&lt;p&gt;}&lt;/p&gt;&lt;p&gt;}&lt;/p&gt;&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;void&lt;/font&gt;&lt;font size="2"&gt; WriteProcessingInstructions()&lt;p&gt;{&lt;/p&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;if&lt;/font&gt;&lt;font size="2"&gt; (&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;this&lt;/font&gt;&lt;font size="2"&gt;._processingInstructions != &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;null&lt;/font&gt;&lt;font size="2"&gt;)&lt;p&gt;{&lt;/p&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;foreach&lt;/font&gt;&lt;font size="2"&gt;(&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;string&lt;/font&gt;&lt;font size="2"&gt; key &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;in&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;this&lt;/font&gt;&lt;font size="2"&gt;._processingInstructions.AllKeys)&lt;p&gt;{&lt;/p&gt;&lt;p&gt;WriteProcessingInstruction(key, &lt;font color="#0000ff" size="2"&gt;this&lt;/font&gt;&lt;font size="2"&gt;._processingInstructions[key]);&lt;p&gt;}&lt;/p&gt;&lt;p&gt;}&lt;/p&gt;&lt;p&gt;}&lt;/p&gt;&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;if&lt;/font&gt;&lt;font size="2"&gt; (&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;this&lt;/font&gt;&lt;font size="2"&gt;._processingInstructions != &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;null&lt;/font&gt;&lt;font size="2"&gt;)&lt;p&gt;{&lt;/p&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;foreach&lt;/font&gt;&lt;font size="2"&gt;(&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;string&lt;/font&gt;&lt;font size="2"&gt; key &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;in&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;this&lt;/font&gt;&lt;font size="2"&gt;._processingInstructions.AllKeys)&lt;p&gt;{&lt;/p&gt;&lt;p&gt;WriteProcessingInstruction(key, &lt;font color="#0000ff" size="2"&gt;this&lt;/font&gt;&lt;font size="2"&gt;._processingInstructions[key]);&lt;p&gt;}&lt;/p&gt;&lt;p&gt;}&lt;/p&gt;&lt;p&gt;}&lt;/p&gt;&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;foreach&lt;/font&gt;&lt;font size="2"&gt;(&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;string&lt;/font&gt;&lt;font size="2"&gt; key &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;in&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;this&lt;/font&gt;&lt;font size="2"&gt;._processingInstructions.AllKeys)&lt;p&gt;{&lt;/p&gt;&lt;p&gt;WriteProcessingInstruction(key, &lt;font color="#0000ff" size="2"&gt;this&lt;/font&gt;&lt;font size="2"&gt;._processingInstructions[key]);&lt;p&gt;}&lt;/p&gt;&lt;p&gt;}&lt;/p&gt;&lt;p&gt;}&lt;/p&gt;&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;this&lt;/font&gt;&lt;font size="2"&gt;._processingInstructions[key]);&lt;p&gt;}&lt;/p&gt;&lt;p&gt;}&lt;/p&gt;&lt;p&gt;}&lt;/p&gt;&lt;/font&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description></item><item><title>Re: Creating InfoPath XML from C#</title><link>https://www.infopathdev.com:443/forums/thread/10460.aspx</link><pubDate>Wed, 13 Sep 2006 09:09:44 GMT</pubDate><guid isPermaLink="false">033a2e2d-04e2-4a9d-be01-a4634161eefd:10460</guid><dc:creator>victorv</dc:creator><slash:comments>0</slash:comments><comments>https://www.infopathdev.com:443/forums/thread/10460.aspx</comments><wfw:commentRss>https://www.infopathdev.com:443/forums/commentrss.aspx?SectionID=41&amp;PostID=10460</wfw:commentRss><description>Hey Matt,&lt;br /&gt;&lt;br /&gt;What is the benefit? I need to generate InfoPath forms from code (.NET 1.1) that can be edited later on by a human to complete.&lt;br /&gt;&lt;br /&gt;After &lt;i&gt;much&lt;/i&gt; searching and trying, I came to the following conclusions:&lt;br /&gt;&lt;br /&gt;1. out-of-the-box XmlSerialzation generally cannot be used with InfoPath forms.&lt;br /&gt;&lt;br /&gt;2. The C# code class, generated by XSD.exe, is generally not easy to use if the schema of the InfoPath template uses for example DateTime fields. XSD.exe generates a valuetype DateTime which may generate a FormatException for an empty or null field when serializing.&lt;br /&gt;For serialization to work, a property based C# must be generated where empty fields can be deserialized correctly; also empty or null string fields need to produce an empty XML node instead of no XML node (I am working on both these issues).&lt;br /&gt;&lt;br /&gt;3. XmlSerialization in .NET 1.1 sucks, because field order is not guaranteed. The only solution I see now is to extract the on-the-fly-generated XmlSerializationWriter and change the writing order of fields by hand. I am planning to use the utility SGEN.exe &lt;a target="_blank" href=http://clariusconsulting.net/blogs/kzu/archive/2004/10/21/XGenToolRelease.aspx&gt;http://clariusconsulting.net/blogs/kzu/archive/2004/10/21/XGenToolRelease.aspx&lt;/a&gt;) to extract the writer code.&lt;br /&gt;XmlSerilization in .NET 2.0 is somewhat better because support for order and nullable types can be used for value types.&lt;br /&gt;&lt;br /&gt;</description></item><item><title>Re: Creating InfoPath XML from C#</title><link>https://www.infopathdev.com:443/forums/thread/10459.aspx</link><pubDate>Fri, 08 Sep 2006 17:23:40 GMT</pubDate><guid isPermaLink="false">033a2e2d-04e2-4a9d-be01-a4634161eefd:10459</guid><dc:creator>Matt Faus</dc:creator><slash:comments>0</slash:comments><comments>https://www.infopathdev.com:443/forums/thread/10459.aspx</comments><wfw:commentRss>https://www.infopathdev.com:443/forums/commentrss.aspx?SectionID=41&amp;PostID=10459</wfw:commentRss><description>Hey Victor,&lt;br /&gt;&lt;br /&gt;This sounds like a very interesting scenario. How are you benefitting from generating this XML from C# using the built-in serialization methods?&lt;br /&gt;&lt;br /&gt;The problem you're hitting seems like a bug in the XmlSerialization class.  The only advice I have in that regard is that maybe you should write your own serialization objects to make sure that it works correctly.  If you do it generically enough you should be able to use them for any objects, and you could even share them with the community for all to use!&lt;br /&gt;&lt;br /&gt;Please let us know how this works out!</description></item><item><title>Creating InfoPath XML from C#</title><link>https://www.infopathdev.com:443/forums/thread/5831.aspx</link><pubDate>Thu, 07 Sep 2006 10:00:41 GMT</pubDate><guid isPermaLink="false">033a2e2d-04e2-4a9d-be01-a4634161eefd:5831</guid><dc:creator>victorv</dc:creator><slash:comments>0</slash:comments><comments>https://www.infopathdev.com:443/forums/thread/5831.aspx</comments><wfw:commentRss>https://www.infopathdev.com:443/forums/commentrss.aspx?SectionID=41&amp;PostID=5831</wfw:commentRss><description>I have a problem writing XML from C# (.NET 1.1) that can be loaded into InfoPath and is valid according to the template's schema (XSD): XmlSerialization is mixing up fields in the output.&lt;br /&gt;&lt;br /&gt;Goal I want to achieve: C# (.NET 1.1) code that writes XML which is valid according to the InfoPath template schema.&lt;br /&gt;&lt;br /&gt;What I did:&lt;br /&gt;1. Developed an InfoPath template.&lt;br /&gt;2. Used the schema (XSD) from the template to infer a C# class using XSD.exe.&lt;br /&gt;3. Developed code to fill an instance of the C# class and serialize it to XML using XmlSerialization. (NOTE: some extra code fluff is necessary to make sure the correct processing instructions (template location) and every field are present in the XML output)&lt;br /&gt;4. Try to load the XML into InfoPath. &lt;br /&gt;&lt;br /&gt;Step 4 &lt;b&gt;&lt;font color="red"&gt;fails&lt;/font id="red"&gt;&lt;/b&gt; because the XML is &lt;i&gt;not valid&lt;/i&gt; according to the template's schema. Some fields appear in a &lt;i&gt;different order &lt;/i&gt;in the XML output while the schema dictates an order (sequence).&lt;br /&gt;&lt;br /&gt;XmlSerialization uses reflection on the C# class to create a Reader and Writer on the fly to facilitate serialization. Unfortunately, it screws up the order of fields in the output. &lt;br /&gt;And what a pain in the ass it is, because it screws up my development workflow where form 'typesafe' C# code is created by tooling from the InfoPath template.&lt;br /&gt;&lt;br /&gt;Does anyone have an idea to create XML from code that is valid according to the InfoPath's Template? Typesafe if possible?&lt;br /&gt;&lt;br /&gt;Victor</description></item></channel></rss>