user278618
user278618

Reputation: 20232

Insert line in xml doc

I wanna insert in second line :

<?mso-application progid="Excel.Sheet"?> 

but I'm started to think that it is impossible.

Here is my base code:

 XmlDocument doc = new XmlDocument();


                XmlReader reader = cmd.ExecuteXmlReader();


                doc.LoadXml("<results></results>");


                XmlNode newNode = doc.ReadNode(reader);

                while (newNode != null)
                {
                    doc.DocumentElement.AppendChild(newNode);
                    newNode = doc.ReadNode(reader);

                }

Upvotes: 0

Views: 485

Answers (2)

Thorin Oakenshield
Thorin Oakenshield

Reputation: 14662

Just Try like this

     XmlNode XNode = doc.CreateProcessingInstruction("mso-application ", "progid=\"Excel.Sheet\"");
     doc.AppendChild(XNode);

Upvotes: 2

mmmmmm
mmmmmm

Reputation: 32651

<?mso-application progid="Excel.Sheet"?> is a processing instruction not an element so you need to use the CreateProcessingInstruction Method

Upvotes: 2

Related Questions