Readers Class

Provides utility methods for reading and validating XML content using an XmlReader.

C#
public static class Readers
Inheritance
Readers

Methods

ConfirmNext(XmlReader)

Ensures that more parsing events are available in the reader before attempting to read further. Throws a BindException if the end of the stream is reached unexpectedly.

ConfirmEndOfStream(XmlReader)

Skips any trailing character data (text, whitespace) and confirms that the reader is at the end of the stream. Throws a BindException if additional content is found beyond the expected end.

ConfirmStartElement(XmlReader, XmlQualifiedName)

Confirms that the current node in the XML reader is a start element matching the specified qualified name. Throws a BindException otherwise.

ConfirmEndElement(XmlReader, XmlQualifiedName)

Confirms that the current node in the XML reader is an end element matching the specified qualified name. Throws a BindException otherwise.

SkipCharacters(XmlReader)

Skips any character data (text, whitespace, CDATA sections) in the specified XML reader.

NewResult<T>(IXmlLineInfo, T)

Returns a new BindResult<T> object with the specified value and the specified location information.

NewResultObject(IXmlLineInfo, object)

Returns a new BindResult<T> object with the specified value and the specified location information.

ToXmlLineInfo(XmlReader)

Creates a new IXmlLineInfo object from the specified XML reader.

AsXmlLineInfo(XmlReader)

Gets the IXmlLineInfo object from the specified XML reader, if available.

NewBindExceptionDueToEmptyElement(XmlReader, XmlQualifiedName)

Creates a new BindException for when an element is empty but a required child element was expected.

NewQName(XmlReader)

Creates a XmlQualifiedName from the current node (element or attribute) of the specified XmlReader.

Equals(XmlReader, XmlQualifiedName)

Checks if the qualified name of the current node in the XmlReader matches the specified XmlQualifiedName.

Methods Detail

ConfirmNext(XmlReader)

Ensures that more parsing events are available in the reader before attempting to read further. Throws a BindException if the end of the stream is reached unexpectedly.

C#
public static void ConfirmNext(XmlReader @in)

Parameters

in
XmlReader

The XML reader.

ConfirmEndOfStream(XmlReader)

Skips any trailing character data (text, whitespace) and confirms that the reader is at the end of the stream. Throws a BindException if additional content is found beyond the expected end.

C#
public static void ConfirmEndOfStream(XmlReader @in)

Parameters

in
XmlReader

The XML reader.

ConfirmStartElement(XmlReader, XmlQualifiedName)

Confirms that the current node in the XML reader is a start element matching the specified qualified name. Throws a BindException otherwise.

C#
public static void ConfirmStartElement(XmlReader @in, XmlQualifiedName expectedName)

Parameters

in
XmlReader

The XML reader.

expectedName
XmlQualifiedName

The expected qualified name of the element.

ConfirmEndElement(XmlReader, XmlQualifiedName)

Confirms that the current node in the XML reader is an end element matching the specified qualified name. Throws a BindException otherwise.

C#
public static void ConfirmEndElement(XmlReader @in, XmlQualifiedName expectedName)

Parameters

in
XmlReader

The XML reader.

expectedName
XmlQualifiedName

The expected qualified name of the element.

SkipCharacters(XmlReader)

Skips any character data (text, whitespace, CDATA sections) in the specified XML reader.

C#
public static XmlNodeType SkipCharacters(XmlReader @in)

Parameters

in
XmlReader

The XML reader.

Returns

The XmlNodeType of the current node after skipping any character data.

NewResult<T>(IXmlLineInfo, T)

Returns a new BindResult<T> object with the specified value and the specified location information.

C#
public static BindResult<T> NewResult<T>(IXmlLineInfo info, T value)

Type Parameters

T
class

The type of the result value.

Parameters

info
IXmlLineInfo

The location information.

value
T

The value of the result.

Returns

A new BindResult<T> instance.

NewResultObject(IXmlLineInfo, object)

Returns a new BindResult<T> object with the specified value and the specified location information.

C#
public static object NewResultObject(IXmlLineInfo info, object value)

Parameters

info
IXmlLineInfo

The location information.

value
object

The value of the result.

Returns

A new BindResult<T> instance.

ToXmlLineInfo(XmlReader)

Creates a new IXmlLineInfo object from the specified XML reader.

C#
public static IXmlLineInfo ToXmlLineInfo(XmlReader @in)

Parameters

in
XmlReader

The XML reader.

Returns

The IXmlLineInfo object which is immutable.

AsXmlLineInfo(XmlReader)

Gets the IXmlLineInfo object from the specified XML reader, if available.

C#
public static IXmlLineInfo AsXmlLineInfo(XmlReader @in)

Parameters

in
XmlReader

The XML reader.

Returns

The IXmlLineInfo object that the XML reader object is cast to, or the default IXmlLineInfo object if the cast fails.

NewBindExceptionDueToEmptyElement(XmlReader, XmlQualifiedName)

Creates a new BindException for when an element is empty but a required child element was expected.

C#
public static BindException NewBindExceptionDueToEmptyElement(XmlReader @in, XmlQualifiedName expectedChildElementName)

Parameters

in
XmlReader

The XML reader.

expectedChildElementName
XmlQualifiedName

The name of the element that is expected as the child element.

Returns

NewQName(XmlReader)

Creates a XmlQualifiedName from the current node (element or attribute) of the specified XmlReader.

C#
public static XmlQualifiedName NewQName(XmlReader @in)

Parameters

in
XmlReader

The XML reader.

Returns

A new XmlQualifiedName object representing the name of the current node in the XML reader.

Equals(XmlReader, XmlQualifiedName)

Checks if the qualified name of the current node in the XmlReader matches the specified XmlQualifiedName.

C#
public static bool Equals(XmlReader @in, XmlQualifiedName qName)

Parameters

in
XmlReader

The XML reader.

qName
XmlQualifiedName

The qualified name.

Returns

true if the qualified name of the current node in the XML reader matches the specified qName; otherwise, false.