Hi, I am creating an XML file in C# using a XSD Schema of an InfoPath form.
When I save the IP form without using the code, I get an XML file with the following header:
<?xml version="1.0" encoding="UTF-8"?>
<?mso-infoPathSolution solutionVersion="1.0.0.113" productVersion="14.0.0" PIVersion="1.0.0.0" href="file:///\\Hmfp\mcs-shared\PMU\PMU-shared\Tests\QF%207.5%20PMU%20Project%20Outline%20Form%20F1.0.xsn" name="urn:schemas-microsoft-com:office:infopath:QF-7-5-PMU-Project-Outline-Form-F1-0:-myXSD-2010-07-22T07-48-32" ?>
<?mso-application progid="InfoPath.Document"?>
<my:myFields...
And this file is recognized by InfoPath and uses the correct XSD, thus displaying the XML data in the correct form.
But when I use the code, I get this:
<?xml version="1.0"?>
<myFields...
And this is not recognized nor opened directly by InfoPath; so I would like to insert the two tags in order to keep that functionality, so that the users do not see the difference.
My line of thought is to modify the XML file after it has already been created, saved and closed.
It would be very nice if you could help :D. Thanks in advance..
EDIT: I've finally been able to achieve what I wanted. I made use of both MainMa's and dahlbyk's answers and came up with something that works:
- I let the file get saved like before
- I created an
XmlReader
object from the file - I loaded the
XmlReader
into anXmlDocument
object - I created an
XmlProcessingInstruction
object usingXmlDocument.CreateProcessingInstruction
- I inserted that
PI
in theXmlDoc
usingxmlDoc.InsertAfter(thePI, XmlDoc.FirstChild)
- I then created a second
PI
object - Which I inserted using
xmlDoc.InsertAfter(thePI, XmlDoc.FirstChild.NextSibling)
- Then I saved the XmlDoc in the file, overwriting it
Anyway, your answers helped me understand many things, which made me find the answer, so thank you very much!!