Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 972685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T03:09:44+00:00 2026-05-16T03:09:44+00:00

I am creating an XML file in C# using a XSD Schema of an

  • 0

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 an XmlDocument object
  • I created an XmlProcessingInstruction object using XmlDocument.CreateProcessingInstruction
  • I inserted that PI in the XmlDoc using xmlDoc.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!!

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T03:09:45+00:00Added an answer on May 16, 2026 at 3:09 am

    The first three lines of your first code sample are called XML processing instructions (PI). So if you are creating your output XML with XmlDocument, you can use XmlDocument.CreateProcessingInstruction method to add the required PI.

    If you are serializing into XML, you can also use XmlTextWriter.WriteProcessingInstruction just before serializing the object.

    If for some reasons, you cannot do that, you can also save the file, open it and insert two PI after the first line break, but I highly discourage you to do that, since it will make your code difficult to maintain in future, and slow things down.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the following XML file for creating a layout: <?xml version=1.0 encoding=utf-8?> <LinearLayout
I'm having trouble creating an XML file from XSD using JAXB below is the
I'm creating an XML file using Perl and XML::Simple module. I successfully create the
I am using XML file for creating Context Menu for my ListView. (Please see
I'm creating a program using C# (in ASP.NET environment) that makes an XML file.
Using MSXML4, I am creating and saving an xml file: MSXML2::IXMLDOMDocument2Ptr m_pXmlDoc; //add some
I'm using XML for a config file in PHP (Using SimpleXML), in creating the
I am creating an XML file using the System.Xml.Serialization module. I have a class
I have a DataTable that I'm creating an XML file from using .WriteXML(..), although
Possible Duplicate: Creating a simple XML file using python I want to write a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.