Readers Class
Provides utility methods for reading and validating XML content using an XmlReader.
public static class Readers
- Inheritance
-
Readers
Methods
Confirm |
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. |
Confirm |
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. |
Confirm |
Confirms that the current node in the XML reader is a start element matching the specified qualified name. Throws a BindException otherwise. |
Confirm |
Confirms that the current node in the XML reader is an end element matching the specified qualified name. Throws a BindException otherwise. |
Skip |
Skips any character data (text, whitespace, CDATA sections) in the specified XML reader. |
New |
Returns a new BindResult<T> object with the specified value and the specified location information. |
New |
Returns a new BindResult<T> object with the specified value and the specified location information. |
To |
Creates a new IXmlLineInfo object from the specified XML reader. |
As |
Gets the IXmlLineInfo object from the specified XML reader, if available. |
New |
Creates a new BindException for when an element is empty but a required child element was expected. |
New |
Creates a XmlQualifiedName from the current node (element or attribute) of the specified XmlReader. |
Equals(Xml |
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.
public static void ConfirmNext(XmlReader @in)
Parameters
- in
-
Xml
Reader
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.
public static void ConfirmEndOfStream(XmlReader @in)
Parameters
- in
-
Xml
Reader
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.
public static void ConfirmStartElement(XmlReader @in, XmlQualifiedName expectedName)
Parameters
- in
-
Xml
Reader
The XML reader.
- expectedName
-
Xml
Qualified Name
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.
public static void ConfirmEndElement(XmlReader @in, XmlQualifiedName expectedName)
Parameters
- in
-
Xml
Reader
The XML reader.
- expectedName
-
Xml
Qualified Name
The expected qualified name of the element.
SkipCharacters(XmlReader)
Skips any character data (text, whitespace, CDATA sections) in the specified XML reader.
public static XmlNodeType SkipCharacters(XmlReader @in)
Parameters
- in
-
Xml
Reader
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.
public static BindResult<T> NewResult<T>(IXmlLineInfo info, T value)
Type Parameters
- T
-
class
The type of the result value.
Parameters
- info
-
IXml
Line Info
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.
public static object NewResultObject(IXmlLineInfo info, object value)
Parameters
- info
-
IXml
Line Info
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.
public static IXmlLineInfo ToXmlLineInfo(XmlReader @in)
Parameters
- in
-
Xml
Reader
The XML reader.
Returns
The IXmlLineInfo object which is immutable.
AsXmlLineInfo(XmlReader)
Gets the IXmlLineInfo object from the specified XML reader, if available.
public static IXmlLineInfo AsXmlLineInfo(XmlReader @in)
Parameters
- in
-
Xml
Reader
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.
public static BindException NewBindExceptionDueToEmptyElement(XmlReader @in, XmlQualifiedName expectedChildElementName)
Parameters
- in
-
Xml
Reader
The XML reader.
- expectedChildElementName
-
Xml
Qualified Name
The name of the element that is expected as the child element.
Returns
The new BindException.
NewQName(XmlReader)
Creates a XmlQualifiedName from the current node (element or attribute) of the specified XmlReader.
public static XmlQualifiedName NewQName(XmlReader @in)
Parameters
- in
-
Xml
Reader
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.
public static bool Equals(XmlReader @in, XmlQualifiedName qName)
Parameters
- in
-
Xml
Reader
The XML reader.
- qName
-
Xml
Qualified Name
The qualified name.
Returns
true
if the qualified name of the current node in the XML reader
matches the specified qName
; otherwise,
false
.