Writes this node to an XmlWriter. : Nodes « XML LINQ « C# / C Sharp






Writes this node to an XmlWriter.

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

public class MainClass
{
    public static void Main()
    {
        StringBuilder sb = new StringBuilder();
        XmlWriterSettings xws = new XmlWriterSettings();
        xws.OmitXmlDeclaration = true;
        xws.Indent = true;

        using (XmlWriter xw = XmlWriter.Create(sb, xws))
        {
            xw.WriteStartElement("Root");
            XElement child1 = new XElement("A",
                new XElement("GrandChild", "some content")
            );
            child1.WriteTo(xw);
            XElement child2 = new XElement("AnotherChild",
                new XElement("GrandChild", "different content")
            );
            child2.WriteTo(xw);
            xw.WriteEndElement();
        }
        Console.WriteLine(sb.ToString());
    }
}

   
    
  








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.Replaces this node with the specified content.
21.Returns the XML for this node, optionally disabling formatting.
22.Returns the indented XML for this node.