Table of Contents

Class XmlReaderExtensions

Namespace
Cuemon.Extensions.Xml
Assembly
Cuemon.Extensions.Xml.dll

Extension methods for the System.Xml.XmlReader class.

public static class XmlReaderExtensions
Inheritance
Object
XmlReaderExtensions

Methods

Chunk(XmlReader, Int32, Action<XmlWriterSettings>)

Creates and returns a sequence of chunked System.Xml.XmlReader instances with a maximum of the specified size of XML node elements located on a depth of 1.

public static IEnumerable<XmlReader> Chunk(this XmlReader reader, int size = 128, Action<XmlWriterSettings> setup = null)

Parameters

reader XmlReader

The System.Xml.XmlReader to extend.

size Int32

The amount of XML node elements allowed per System.Xml.XmlReader object. Default is 128 XML node element.

setup Action<XmlWriterSettings>

The System.Xml.XmlWriterSettings which may be configured.

Returns

IEnumerable<XmlReader>

An sequence of System.Xml.XmlReader instances that contains no more than the specified size of XML node elements from the reader object.

Exceptions

System.ArgumentNullException

reader is null.

System.ArgumentException

The System.Xml.XmlReader.Read method of the reader object has already been called.

MoveToFirstElement(XmlReader)

Moves the reader to the first element.

public static bool MoveToFirstElement(this XmlReader reader)

Parameters

reader XmlReader

The System.Xml.XmlReader to extend.

Returns

Boolean

true if an element exists (the reader moves to the first element), otherwise, false (the reader has reached System.Xml.XmlReader.EOF).

Exceptions

System.ArgumentNullException

reader is null.

System.ArgumentException

The System.Xml.XmlReader.Read method of the reader object has already been called.

ToHierarchy(XmlReader)

Converts the XML hierarchy of the reader into an IHierarchy<T>.

public static IHierarchy<DataPair> ToHierarchy(this XmlReader reader)

Parameters

reader XmlReader

The System.Xml.XmlReader to extend.

Returns

IHierarchy<DataPair>

An IHierarchy{DataPair} implementation.

Exceptions

System.ArgumentNullException

reader cannot be null.

ToStream(XmlReader, Action<XmlCopyOptions>)

Copies everything from the specified reader and returns the result as an XML stream.

public static Stream ToStream(this XmlReader reader, Action<XmlCopyOptions> setup = null)

Parameters

reader XmlReader

The System.Xml.XmlReader to extend.

setup Action<XmlCopyOptions>

The XmlCopyOptions which may be configured.

Returns

Stream

A System.IO.Stream holding an exact copy of the source reader.

Exceptions

System.ArgumentNullException

reader is null.

ToStream(XmlReader, Action<XmlWriter, XmlReader, DisposableOptions>, Action<XmlCopyOptions>)

Copies the specified reader using the specified delegate copier and returns the result as an XML stream.

public static Stream ToStream(this XmlReader reader, Action<XmlWriter, XmlReader, DisposableOptions> copier, Action<XmlCopyOptions> setup = null)

Parameters

reader XmlReader

The System.Xml.XmlReader to extend.

copier Action<XmlWriter, XmlReader, DisposableOptions>

The delegate that will create an in-memory copy of reader as a XML stream.

setup Action<XmlCopyOptions>

The XmlCopyOptions which may be configured.

Returns

Stream

A System.IO.Stream holding the XML copied by the delegate copier from the source reader.

Exceptions

System.ArgumentNullException

reader is null - or - copier is null.