CSharp - Creating Processing Instruction with XProcessingInstruction

Description

Creating Processing Instruction with XProcessingInstruction

Demo

using System;
using System.Linq;
using System.Xml.Linq;
using System.Collections.Generic;

class Program/*w ww . j  av  a  2s.  co m*/
{
    static void Main(string[] args){
          XDocument xDocument = new XDocument(
            new XProcessingInstruction("BookCataloger", "out-of-print"),
            new XElement("Books",
              new XElement("Book",
                new XProcessingInstruction("ParticipantDeleter", "delete"),
                new XElement("FirstName", "Joe"),
                new XElement("LastName", "Ruby"))));
    
          Console.WriteLine(xDocument);
    }
}

Result

In the code, we added a processing instruction to both the document and the Book element.

Related Topics