Click or drag to resize

XmlUtilsWriteShallowNode Method

This method is useful for streaming transformation with the XmlReader and the XmlWriter. It pushes through single nodes in the stream. The XmlWriter.WriteNode method is useful in pulling from an XmlReader and pushing to an XmlWriter to achieve this, but it does have a limitation in that it writes the current node and all its children to the XmlWriter without providing more fine-grained control.

Namespace:  PDTec.IceNet.Sdk.Utils
Assembly:  PDTec.IceNet.Sdk (in PDTec.IceNet.Sdk.dll) Version: 7.2.0.0 (7.2.7583.15464)
Syntax
C#
public static void WriteShallowNode(
	XmlReader reader,
	XmlWriter writer
)

Parameters

reader
Type: System.XmlXmlReader
writer
Type: System.XmlXmlWriter
Examples
static void AddElementWithWriteShallowNode()
{
    XmlWriterSettings settings = new XmlWriterSettings();
    settings.Indent = true;

    using (XmlReader reader = XmlReader.Create("movies.xml"))
    {
        using (XmlWriter writer = XmlWriter.Create(Console.Out, settings))
        {
            while (reader.Read())
            {
                if (reader.IsStartElement("dvd") && reader.GetAttribute("genre") == "action")
                {
                    //Write the dvd element
                    XmlUtils.WriteShallowNode(reader, writer);
                    //Now add a new publisher element to the output
                    writer.WriteElementString("publisher", "metal.sword.com", "Samurai Films");
                }
                else
                {
                    XmlUtils.WriteShallowNode(reader, writer);
                }
            }
        }
    }
}
See Also