Mono Class Library: System.Xml.XmlWriter Overview | Members

System.Xml.XmlWriter.WriteNode Method

Writes the node found at the current position of the specified System.Xml.XmlReader, and all sub-nodes. [Edit]

public virtual void WriteNode (XmlReader reader, bool defattr)

Parameters

reader
A System.Xml.XmlReader from which to copy the attributes. [Edit]
defattr
A bool where true specifies to copy the default attributes from reader; otherwise, false. [Edit]

Exceptions

TypeReason
ArgumentNullExceptionreader is null. [Edit]
InvalidOperationExceptionThe XmlWriter.WriteState is WriteState.Closed. [Edit]

Remarks

Operation
After the nodes are read, reader is moved to the next node at the same depth as the current node.

If reader is in the ReadState.InitialXmlReader.ReadState, this method moves reader to the end of the stream. If reader is in the ReadState.EndOfFileXmlReader.ReadState, this method is non-operational.

Note to Inheritors
Override this method to customize the behavior of this method in types derived from the System.Xml.XmlWriter class.

Usage
Use this method to write the node found at the current position and all sub-nodes.

[Edit]

Example

The following example uses a System.Xml.XmlTextReader and a System.Xml.XmlTextWriter to copy an XML file, specified in the command line, to the console.

C# Example
using System;
using System.Xml;

public class Copier {

  public static void Main(string[] args) {

    XmlTextReader xtReader = new XmlTextReader(args[0]);
    XmlTextWriter xtWriter =
      new XmlTextWriter(Console.Out);
    xtWriter.WriteNode(xtReader, false);
    xtWriter.Close();
    xtReader.Close();
  }
}

Requirements

Namespace: System.Xml
Assembly: System.Xml (in System.Xml.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0