Replaces this node with the specified content. : Nodes « XML LINQ « C# / C Sharp






Replaces this node with the specified content.

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

public class MainClass{
   public static void Main(){
        XElement xmlTree = new XElement("Root",
            new XElement("A1", "A1 content"),
            new XElement("A2", "A2 content"),
            new XElement("A3", "A3 content"),
            new XElement("A4", "A4 content"),
            new XElement("A5", "A5 content")
        );
        XElement child3 = xmlTree.Element("A3");
        child3.ReplaceWith(
            new XElement("NewA", "new content")
        );
        Console.WriteLine(xmlTree);
   }
}

   
    
  








Related examples in the same category

1.Calling the Only Nodes Prototype
2.Traversing Backward from an XElement Object via the PreviousNode Property
3.Adds the specified content immediately after this node.
4.Adds the specified content immediately before this node.
5.Returns a collection of the ancestor elements of this node.
6.Returns a filtered collection of the ancestor elements of this node.
7.Creates an XmlReader for this node.
8.Use hard coded xsl to convert xml document
9.Returns a collection of the sibling elements after this node, in document order.
10.Returns a filtered collection of the sibling elements after this node, in document order.
11.Returns a collection of the sibling elements before this node, in document order.
12.Returns a filtered collection of the sibling elements before this node, in document order.
13.Determines if the current node appears after a specified node in terms of document order.
14.Determines if the current node appears before a specified node in terms of document order.
15.Gets the next sibling node of this node.
16.Returns a collection of the sibling nodes after this node, in document order.
17.Returns a collection of the sibling nodes before this node, in document order.
18.Gets the previous sibling node of this node.
19.Removes this node from its parent.
20.Returns the XML for this node, optionally disabling formatting.
21.Returns the indented XML for this node.
22.Writes this node to an XmlWriter.