C#: Modifying the header of an XML file -


I am creating an XML file in C # using an XSD schema of an InfoPath form.

When I save the IP form without using the code, I get an XML file with the following heading:

   

and this file is recognized by InfoPath and uses the correct XSD, thus displaying XML data correctly.

But when I use the code, I get this:

   

and this is not recognized and is not opened directly by Infopaith; So I would like to include two tags to keep that functionality so that users do not see the difference.

Thought that after modifying my line XML file it has already been created, saved and closed.

If you can help, it would be great: D. Thanks in advance ..

Edit: I have finally been able to get what I wanted to do for both of Maname and Dahlbeke's answers Used and came up with things that work:

  • I had saved the file as before
  • I created the XmlReader file I created the XmlReader in an XmlDocument object
  • I created PI in the < Code> PI
  • < xmlDoc.InsertAfter (thePI, XmlDoc.FirstChild) using xmldoc
  • Then I created a second PI object
  • I inserted using xmlDoc.InsertAfter (thePI, XmlDoc.FirstChild.NextSibling)
  • Then I saved the XmlDoc in the file, overwriting it

Anyway, your answer helped me understand many things, which gave me the answer, thanks so much!

The first three of the first sample code samples of the XML processing instructions (PI ). So if you make your output XML from XmlDocument , then you can use the method to add the required PI.

If you are serialing in XML, then you object.

For some reasons, you can not do this, you can save the file, open it, and put two pi after the first line segment, but I very disappointed < / Strong> To do this, because it will be difficult to keep your code in the future, and slow things down


Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -