System.Xml.XmlReader Class

public abstract class XmlReader

Base Types

Object
  XmlReader

Assembly

System.Xml

Library

XML

Summary

Represents a reader that provides non-cached, forward-only access to XML data.

Description

This class provides forward-only, read-only access to a stream of XML data. This class enforces the rules of well-formed XML but does not perform data validation.

This class conforms to the W3C Extensible Markup Language (XML) 1.0 and the Namespaces in XML recommendations.

A given set of XML data is modeled as a tree of nodes. The different types of nodes are specified in the XmlNodeType enumeration. The reader is advanced to the next node using the System.Xml.XmlReader.Read method. The current node refers to the node on which the reader is positioned. The following table lists the node properties exposed for the current node.

PropertyDescription
AttributeCount The number of attributes on the node.
BaseUriThe base URI of the node.
DepthThe depth of the node in the tree.
HasAttributesWhether the node has attributes.
HasValueWhether the node can have a text value.
IsDefaultWhether an Attribute node was generated from the default value defined in the DTD or schema.
IsEmptyElementWhether an Element node is empty.
LocalNameThe local name of the node.
NameThe qualified name of the node, equal to Prefix :LocalName .
NamespaceUriThe URI defining the namespace associated with the node.
NodeTypeThe XmlNodeType of the node.
PrefixA shorthand reference to the namespace associated with the node.
QuoteCharThe quotation mark character used to enclose the value of an attribute.
ValueThe text value of the node.
XmlLangThe xml:lang scope within which the node resides.
This class does not expand default attributes or general entities. Any general entities encountered are returned as a single empty EntityReference node.

This class checks that a Document Type Definition (DTD) is well-formed, but does not validate using the DTD.

To read strongly typed data, use the XmlConvert class.

This class throws a XmlException on XML parse errors. After an exception is thrown, the state of the reader is not predictable. For example, the reported node type might be different than the actual node type of the current node.

[Note: This class is abstract and implemented in the XmlTextReader class.

]

Attributes

DefaultMemberAttribute("Item")

See Also

System.Xml Namespace

Members

XmlReader Constructors

XmlReader Constructor

XmlReader Methods

XmlReader.Close Method
XmlReader.GetAttribute(System.String) Method
XmlReader.GetAttribute(System.String, System.String) Method
XmlReader.GetAttribute(int) Method
XmlReader.IsName Method
XmlReader.IsNameToken Method
XmlReader.IsStartElement(System.String, System.String) Method
XmlReader.IsStartElement(System.String) Method
XmlReader.IsStartElement() Method
XmlReader.LookupNamespace Method
XmlReader.MoveToAttribute(int) Method
XmlReader.MoveToAttribute(System.String, System.String) Method
XmlReader.MoveToAttribute(System.String) Method
XmlReader.MoveToContent Method
XmlReader.MoveToElement Method
XmlReader.MoveToFirstAttribute Method
XmlReader.MoveToNextAttribute Method
XmlReader.Read Method
XmlReader.ReadAttributeValue Method
XmlReader.ReadElementString(System.String, System.String) Method
XmlReader.ReadElementString(System.String) Method
XmlReader.ReadElementString() Method
XmlReader.ReadEndElement Method
XmlReader.ReadInnerXml Method
XmlReader.ReadOuterXml Method
XmlReader.ReadStartElement() Method
XmlReader.ReadStartElement(System.String) Method
XmlReader.ReadStartElement(System.String, System.String) Method
XmlReader.ReadString Method
XmlReader.ResolveEntity Method
XmlReader.Skip Method

XmlReader Properties

XmlReader.AttributeCount Property
XmlReader.BaseURI Property
XmlReader.CanResolveEntity Property
XmlReader.Depth Property
XmlReader.EOF Property
XmlReader.HasAttributes Property
XmlReader.HasValue Property
XmlReader.IsDefault Property
XmlReader.IsEmptyElement Property
XmlReader.Item(int) Property
XmlReader.Item(System.String) Property
XmlReader.Item(System.String, System.String) Property
XmlReader.LocalName Property
XmlReader.Name Property
XmlReader.NameTable Property
XmlReader.NamespaceURI Property
XmlReader.NodeType Property
XmlReader.Prefix Property
XmlReader.QuoteChar Property
XmlReader.ReadState Property
XmlReader.Value Property
XmlReader.XmlLang Property
XmlReader.XmlSpace Property


XmlReader Constructor

protected XmlReader();

Summary

Constructs a new instance of the XmlReader class.

See Also

System.Xml.XmlReader Class, System.Xml Namespace

XmlReader.Close Method

public abstract void Close();

Summary

Changes the System.Xml.XmlReader.ReadState to System.Xml.ReadState.Closed.

Description

[Behaviors: This method releases any resources allocated by the current instance, changes the System.Xml.XmlReader.ReadState to System.Xml.ReadState.Closed, and calls the Close method of any underlying Stream or TextReader instance. ]

[Overrides: This method must be overridden in order to provide the functionality described above, as there is no default implementation. ]

See Also

System.Xml.XmlReader Class, System.Xml Namespace

XmlReader.GetAttribute(System.String) Method

public abstract string GetAttribute(string name);

Summary

Returns the value of the attribute with the specified qualified name.

Parameters

name
A String specifying the qualified name of the attribute.

Return Value

A String containing the value of the specified attribute, or null if the attribute is not found.

Description

[Behaviors: This method does not move the reader. ]

[Overrides: This method must be overridden in order to provide the functionality described above, as there is no default implementation. ]

Example

For an example demonstrating this method, see System.Xml.XmlTextReader.GetAttribute(System.Int32)(String, String).

See Also

System.Xml.XmlReader Class, System.Xml Namespace

XmlReader.GetAttribute(System.String, System.String) Method

public abstract string GetAttribute(string name, string namespaceURI);

Summary

Returns the value of the attribute with the specified local name and namespace URI.

Parameters

name
A String specifying the local name of the attribute.
namespaceURI
A String specifying the namespace URI of the attribute.

Return Value

A String containing the value of the specified attribute, or null if the attribute is not found.

Description

[Behaviors: This method does not move the reader. ]

[Overrides: This method must be overridden in order to provide the functionality described above, as there is no default implementation. ]

Example

For an example demonstrating this method, see System.Xml.XmlTextReader.GetAttribute(System.Int32)(String, String).

See Also

System.Xml.XmlReader Class, System.Xml Namespace

XmlReader.GetAttribute(int) Method

public abstract string GetAttribute(int i);

Summary

Returns the value of the attribute with the specified index relative to the containing element.

Parameters

i
A Int32 specifying the zero-based index of the attribute relative to the containing element.

Return Value

A String containing the value of the specified attribute.

Exceptions

Exception TypeCondition
ArgumentOutOfRangeExceptioni is less than 0, or greater than or equal to the System.Xml.XmlReader.AttributeCount of the containing element.

Description

[Behaviors: This method does not move the reader. ]

[Overrides: This method must be overridden in order to provide the functionality described above, as there is no default implementation. ]

Example

For an example demonstrating this method, see System.Xml.XmlTextReader.GetAttribute(System.Int32)(String, String).

See Also

System.Xml.XmlReader Class, System.Xml Namespace

XmlReader.IsName Method

public static bool IsName(string str);

Summary

Determines whether the specified string is a valid XML name.

Parameters

str
A String specifying the name to validate.

Return Value

A Boolean where true indicates the name is valid; otherwise, false .

Description

[Note: This method uses the W3C XML 1.0 Recommendation (http://www.w3.org/TR/2000/REC-xml-20001006#NT-Name) to determine whether the name is valid.

]

See Also

System.Xml.XmlReader Class, System.Xml Namespace

XmlReader.IsNameToken Method

public static bool IsNameToken(string str);

Summary

Determines whether the specified string is a valid XML name token (Nmtoken).

Parameters

str
A String specifying the name to validate.

Return Value

A Boolean where true indicates the name is valid; otherwise false .

Description

[Note: This method uses the W3C XML 1.0 Recommendation (http://www.w3.org/TR/2000/REC-xml-20001006#NT-Nmtoken ) to determine whether the name token is valid.

]

See Also

System.Xml.XmlReader Class, System.Xml Namespace

XmlReader.IsStartElement(System.String, System.String) Method

public virtual bool IsStartElement(string localname, string ns);

Summary

Determines if a node containing content is an Element node with the specified local name and namespace URI.

Parameters

localname
A String specifying the local name of an element.
ns
A String specifying the namespace URI associated with the element.

Return Value

A Boolean where true indicates the node is an Element node with the specified local name and namespace URI; false otherwise.

Exceptions

Exception TypeCondition
XmlExceptionAn error occurred while parsing the XML.

Description

[Behaviors: As described above. ]

[Default: This method calls the System.Xml.XmlReader.MoveToContent method, which determines whether the current node can contain content and, if not, moves the reader to the next content node or the end of the input stream. When the reader is positioned on a content node, the node is checked to determine if it is an Element node with System.Xml.XmlReader.LocalName and System.Xml.XmlReader.NamespaceURI properties equal to localname and ns, respectively. ]

[Overrides: Override this method to customize the behavior of this method in types derived from the XmlReader class. ]

[Usage: Use this method to determine whether the node returned by the System.Xml.XmlReader.MoveToContent method is an Element node with the specified local name and namespace URI. ]

See Also

System.Xml.XmlReader Class, System.Xml Namespace

XmlReader.IsStartElement(System.String) Method

public virtual bool IsStartElement(string name);

Summary

Determines if a node containing content is an Element node with the specified qualified name.

Parameters

name
A String specifying the qualified name of an element.

Return Value

A Boolean where true indicates the node is an Element node with the specified name; false otherwise.

Exceptions

Exception TypeCondition
XmlExceptionAn error occurred while parsing the XML.

Description

[Behaviors: As described above. ]

[Default: This method calls the System.Xml.XmlReader.MoveToContent method, which determines whether the current node can contain content and, if not, moves the reader to the next content node or the end of the input stream. When the reader is positioned on a content node, the node is checked to determine if it is an Element node with a System.Xml.XmlReader.Name property equal to name.]

[Overrides: Override this method to customize the behavior of this method in types derived from the XmlReader class. ]

[Usage: Use this method to determine whether the node returned by the System.Xml.XmlReader.MoveToContent method is an Element node with the specified name. ]

See Also

System.Xml.XmlReader Class, System.Xml Namespace

XmlReader.IsStartElement() Method

public virtual bool IsStartElement();

Summary

Determines if a node containing content is an Element node.

Return Value

A Boolean where true indicates the node is an Element node; false otherwise.

Exceptions

Exception TypeCondition
XmlExceptionAn error occurred while parsing the XML.

Description

[Behaviors: As described above.]

[Default: This method calls the System.Xml.XmlReader.MoveToContent method, which determines whether the current node can contain content and, if not, moves the reader to the next content node or the end of the input stream. When the reader is positioned on a content node, the node is checked to determine if it is an Element node. ]

[Overrides: Override this method to customize the behavior of this method in types derived from the XmlReader class. ]

[Usage: Use this method to determine whether the node returned by the System.Xml.XmlReader.MoveToContent method is an Element node. ]

See Also

System.Xml.XmlReader Class, System.Xml Namespace

XmlReader.LookupNamespace Method

public abstract string LookupNamespace(string prefix);

Summary

Resolves a namespace prefix in the scope of the current element.

Parameters

prefix
A String specifying the prefix whose namespace URI is to be resolved. To return the default namespace, specify System.String.Empty.

Return Value

A String containing the namespace URI to which the prefix maps. If prefix is not in System.Xml.XmlReader.NameTable or no matching namespace is found, null is returned.

Description

[Behaviors: As described above. ]

[Overrides: This method must be overridden in order to provide the functionality described above, as there is no default implementation. ]

See Also

System.Xml.XmlReader Class, System.Xml Namespace

XmlReader.MoveToAttribute(int) Method

public abstract void MoveToAttribute(int i);

Summary

Moves the position of the current instance to the attribute with the specified index relative to the containing element.

Parameters

i
A Int32 specifying the zero-based index of the attribute relative to the containing element.

Exceptions

Exception TypeCondition
ArgumentOutOfRangeExceptioni is less than 0 or greater than or equal to the System.Xml.XmlReader.AttributeCount of the containing element.

Description

[Behaviors: After calling this method, the System.Xml.XmlReader.Name, System.Xml.XmlReader.NamespaceURI, and System.Xml.XmlReader.Prefix properties reflect the properties of current attribute.]

[Overrides: This method must be overridden in order to provide the functionality described above, as there is no default implementation. ]

See Also

System.Xml.XmlReader Class, System.Xml Namespace

XmlReader.MoveToAttribute(System.String, System.String) Method

public abstract bool MoveToAttribute(string name, string ns);

Summary

Moves the position of the current instance to the attribute with the specified local name and namespace URI.

Parameters

name
A String specifying the local name of the attribute.
ns
A String specifying the namespace URI of the attribute.

Return Value

A Boolean where true indicates the attribute was found; otherwise, false . If false , the position of the current instance does not change.

Description

[Behaviors: After calling this method, the System.Xml.XmlReader.Name, System.Xml.XmlReader.NamespaceURI, and System.Xml.XmlReader.Prefix properties reflect the properties of current attribute.]

[Overrides: This method must be overridden in order to provide the functionality described above, as there is no default implementation. ]

See Also

System.Xml.XmlReader Class, System.Xml Namespace

XmlReader.MoveToAttribute(System.String) Method

public abstract bool MoveToAttribute(string name);

Summary

Moves the position of the current instance to the attribute with the specified qualified name.

Parameters

name
A String specifying the qualified name of the attribute.

Return Value

A Boolean where true indicates the attribute was found; otherwise, false . If false , the reader's position does not change.

Description

[Behaviors: After calling this method, the System.Xml.XmlReader.Name, System.Xml.XmlReader.NamespaceURI, and System.Xml.XmlReader.Prefix properties reflect the properties of current attribute.]

[Overrides: This method must be overridden in order to provide the functionality described above, as there is no default implementation. ]

See Also

System.Xml.XmlReader Class, System.Xml Namespace

XmlReader.MoveToContent Method

public virtual XmlNodeType MoveToContent();

Summary

Determines whether the current node can contain content and, if not, moves the position of the current instance to the next content node or the end of the input stream.

Return Value

The XmlNodeType of the content node, or System.Xml.XmlNodeType.None if the position of the reader has reached the end of the input stream.

Exceptions

Exception TypeCondition
XmlExceptionAn error occurred while parsing the XML.

Description

[Note: The following members of XmlNodeType can contain content: Attribute , CDATA , Element , EndElement , EntityReference , EndEntity , and Text . ]

[Behaviors: As described above.]

[Default: If the current node is an Attribute node, this method moves the position of the reader back to the Element node that owns the attribute. ]

[Overrides: Override this method to customize the behavior of this method in types derived from the XmlReader class. ]

[Usage: Use this method to determine whether the current node can contain content and, if not, move the position of the reader to the next content node. ]

See Also

System.Xml.XmlReader Class, System.Xml Namespace

XmlReader.MoveToElement Method

public abstract bool MoveToElement();

Summary

Moves the position of the current instance to the node that contains the current Attribute node.

Return Value

A Boolean where true indicates the position of the reader was moved; false indicates the reader was not positioned on an Attribute node and therefore the position of the reader was not moved.

Description

[Note: The DocumentType , Element , and XmlDeclaration members of XmlNodeType can contain attributes. ]

[Behaviors: As described above. ]

[Overrides: This method must be overridden in order to provide the functionality described above, as there is no default implementation. ]

See Also

System.Xml.XmlReader Class, System.Xml Namespace

XmlReader.MoveToFirstAttribute Method

public abstract bool MoveToFirstAttribute();

Summary

Moves the position of the current instance to the first attribute associated with the current node.

Return Value

A Boolean where true indicates the current node contains at least one attribute; otherwise, false .

Description

[Behaviors: If System.Xml.XmlReader.AttributeCount is non-zero, the position of the reader moves to the first attribute; otherwise, the position of the reader does not change. ]

[Overrides: This method must be overridden in order to provide the functionality described above, as there is no default implementation. ]

See Also

System.Xml.XmlReader Class, System.Xml Namespace

XmlReader.MoveToNextAttribute Method

public abstract bool MoveToNextAttribute();

Summary

Moves the position of the current instance to the next attribute associated with the current node.

Return Value

A Boolean where true indicates the position of the reader moved to the next attribute; false if there were no more attributes.

Description

[Behaviors: As described above. ]

[Overrides: This method must be overridden in order to provide the functionality described above, as there is no default implementation. ]

See Also

System.Xml.XmlReader Class, System.Xml Namespace

XmlReader.Read Method

public abstract bool Read();

Summary

Moves the position of the current instance to the next node in the stream, exposing its properties.

Return Value

A Boolean where true indicates the node was read successfully, and false indicates there were no more nodes to read.

Exceptions

Exception TypeCondition
XmlExceptionAn error occurred while parsing the XML.

Description

[Behaviors: As described above. ]

[Overrides: This method must be overridden in order to provide the functionality as described herein, as there is no default implementation. ]

[Usage: When a reader is first created and initialized, there is no information available. Calling this method is required to read the first node. ]

See Also

System.Xml.XmlReader Class, System.Xml Namespace

XmlReader.ReadAttributeValue Method

public abstract bool ReadAttributeValue();

Summary

Parses an attribute value into one or more Text , EntityReference , and EndEntity nodes.

Return Value

A Boolean where true indicates the attribute value was parsed, and false indicates the reader was not positioned on an attribute node or all the attribute values have been read.

Description

[Note: To parse an EntityReference node, call the System.Xml.XmlReader.ResolveEntity method. After the node is parsed into child nodes, call the System.Xml.XmlReader.ReadAttributeValue method again to read the value of the entity.

The System.Xml.XmlReader.Depth of an attribute value node is one plus the depth of the attribute node. When general entity references are stepped into or out of, the System.Xml.XmlReader.Depth increments or decrements by one, respectively.

]

[Behaviors: As described above. ]

[Overrides: Implementations that cannot expand general entities should return general entities as a single empty (System.Xml.XmlReader.Value equals System.String.Empty) EntityReference node. ]

[Usage: Use this method after calling System.Xml.XmlReader.MoveToAttribute(System.String) to read through the Text , EntityReference, or EndEntity nodes that make up the attribute value. Call the System.Xml.XmlReader.ResolveEntity method to resolve the EntityReference nodes. ]

See Also

System.Xml.XmlReader Class, System.Xml Namespace

XmlReader.ReadElementString(System.String, System.String) Method

public virtual string ReadElementString(string localname, string ns);

Summary

Reads the contents of a text-only element with the specified local name and namespace URI.

Parameters

localname
A String specifying the local name of an element.
ns
A String specifying the namespace URI associated with the element.

Return Value

A String containing the contents of the element.

Exceptions

Exception TypeCondition
XmlExceptionThe node is not an Element node, the System.Xml.XmlReader.LocalName property of the Element node does not equal localname, or the System.Xml.XmlReader.NamespaceURI property of the Element node does not equal ns, the element does not contain a simple text value, or an error occurred while parsing the XML.

Description

[Behaviors: As described above. ]

[Default: This method calls the System.Xml.XmlReader.MoveToContent method. If the returned node is an Element node, this method compares the System.Xml.XmlReader.LocalName and System.Xml.XmlReader.NamespaceURI properties of the node to localname and ns, respectively. If they are equal, this method calls the System.Xml.XmlReader.ReadString method to read the contents of the element. ]

[Overrides: Override this method to customize the behavior of this method in types derived from the XmlReader class. ]

[Usage: Use this method to read the contents of a text-only element with the specified local name and namespace URI. ]

See Also

System.Xml.XmlReader Class, System.Xml Namespace

XmlReader.ReadElementString(System.String) Method

public virtual string ReadElementString(string name);

Summary

Reads the contents of a text-only element with the specified qualified name.

Parameters

name
A String specifying the qualified name of an element.

Return Value

A String containing the contents of the element.

Exceptions

Exception TypeCondition
XmlExceptionThe node is not an Element node, the System.Xml.XmlReader.Name property of the Element node does not equal name, the element does not contain a simple text value, or an error occurred while parsing the XML.

Description

[Behaviors: As described above. ]

[Default: This method calls the System.Xml.XmlReader.MoveToContent method and, if the returned node is an Element node, compares the System.Xml.XmlReader.Name property of the node to name. If they are equal, this method calls the System.Xml.XmlReader.ReadString method to read the contents of the element. ]

[Overrides: Override this method to customize the behavior of this method in types derived from the XmlReader class. ]

[Usage: Use this method to read the contents of a text-only element with the specified qualified name. ]

See Also

System.Xml.XmlReader Class, System.Xml Namespace

XmlReader.ReadElementString() Method

public virtual string ReadElementString();

Summary

Reads the contents of a text-only element.

Return Value

A String containing the contents of the element.

Exceptions

Exception TypeCondition
XmlExceptionThe node is not an Element node, the element does not contain a simple text value, or an error occurred while parsing the XML.

Description

[Behaviors: As described above. ]

[Default: This method calls the System.Xml.XmlReader.MoveToContent method and, if the returned node is an Element node, calls the System.Xml.XmlReader.ReadString method to read the contents. ]

[Overrides: Override this method to customize the behavior of this method in types derived from the XmlReader class. ]

[Usage: Use this method to read the contents of a text-only element. ]

See Also

System.Xml.XmlReader Class, System.Xml Namespace

XmlReader.ReadEndElement Method

public virtual void ReadEndElement();

Summary

Reads an EndElement node and advances the reader to the next node.

Exceptions

Exception TypeCondition
XmlExceptionThe node is not an EndElement node or an error occurred while parsing the XML.

Description

[Behaviors: As described above. ]

[Default: This method calls the System.Xml.XmlReader.MoveToContent method, which determines whether the current node can contain content and, if not, moves the reader to the next content node or the end of the input stream. The node the reader ends up positioned on is checked to determine if it is an EndElement node. If so, the node is read and the reader is moved to the next node.]

[Overrides: Override this method to customize the behavior of this method in types derived from the XmlReader class. ]

[Usage: Use this method to read an EndElement node and advance the reader to the next node. ]

See Also

System.Xml.XmlReader Class, System.Xml Namespace

XmlReader.ReadInnerXml Method

public abstract string ReadInnerXml();

Summary

Reads the contents of the current node, including child nodes and markup.

Return Value

A String containing the XML content, or System.String.Empty if the current node is neither an element nor attribute, or has no child nodes.

Exceptions

Exception TypeCondition
XmlExceptionThe XML was not well-formed, or an error occurred while parsing the XML.

Description

[Behaviors: The current node and corresponding end node are not returned.

If the current node is an element, after the call to this method, the reader is positioned after the corresponding end element.

If the current node is an attribute, the position of the reader is not changed.

[Note: For a comparison between this method and the System.Xml.XmlReader.ReadOuterXml method, see System.Xml.XmlTextReader.ReadInnerXml.

]

]

[Overrides: This method must be overridden in order to provide the functionality described above, as there is no default implementation. ]

See Also

System.Xml.XmlReader Class, System.Xml Namespace

XmlReader.ReadOuterXml Method

public abstract string ReadOuterXml();

Summary

Reads the current node and its contents, including child nodes and markup.

Return Value

A String containing the XML content, or System.String.Empty if the current node is neither an element nor attribute.

Exceptions

Exception TypeCondition
XmlExceptionThe XML was not well-formed, or an error occurred while parsing the XML.

Description

[Behaviors: The current node and corresponding end node are returned.

If the current node is an element, after the call to this method, the reader is positioned after the corresponding end element.

If the current node is an attribute, the position of the reader is not changed.

[Note: For a comparison between this method and the System.Xml.XmlReader.ReadOuterXml method, see System.Xml.XmlTextReader.ReadInnerXml.

]

]

[Overrides: This method must be overridden in order to provide the functionality described above, as there is no default implementation. ]

See Also

System.Xml.XmlReader Class, System.Xml Namespace

XmlReader.ReadStartElement() Method

public virtual void ReadStartElement();

Summary

Reads an Element node and advances the reader to the next node.

Exceptions

Exception TypeCondition
XmlExceptionThe node is not an Element node or an error occurred while parsing the XML.

Description

[Behaviors: As described above. ]

[Default: This method calls the System.Xml.XmlReader.MoveToContent method, which determines whether the current node can contain content and, if not, moves the reader to the next content node or the end of the input stream. The node the reader ends up positioned on is checked to determine if it is an Element node. If so, the node is read and the reader is moved to the next node. ]

[Overrides: Override this method to customize the behavior of this method in types derived from the XmlReader class. ]

[Usage: Use this method to read an Element node and advance the reader to the next node. ]

See Also

System.Xml.XmlReader Class, System.Xml Namespace

XmlReader.ReadStartElement(System.String) Method

public virtual void ReadStartElement(string name);

Summary

Reads an Element node with the specified qualified name and advances the reader to the next node.

Parameters

name
A String specifying the qualified name of an element.

Exceptions

Exception TypeCondition
XmlExceptionThe node is not an Element node, the System.Xml.XmlReader.Name property of the Element node does not equal name, or an error occurred while parsing the XML.

Description

[Behaviors: As described above. ]

[Default: This method calls the System.Xml.XmlReader.MoveToContent method and, if the returned node is an Element node, compares the System.Xml.XmlReader.Name property of the node to name. If they are equal, this method calls the System.Xml.XmlReader.Read method to read the element and move to the next node. ]

[Overrides: Override this method to customize the behavior of this method in types derived from the XmlReader class. ]

[Usage: Use this method to read an Element node with the specified qualified name, and advance the reader to the next node. ]

See Also

System.Xml.XmlReader Class, System.Xml Namespace

XmlReader.ReadStartElement(System.String, System.String) Method

public virtual void ReadStartElement(string localname, string ns);

Summary

Reads an Element node with the specified local name and namespace URI and advances the reader to the next node.

Parameters

localname
A String specifying the local name of an element.
ns
A String specifying the namespace URI associated with the element.

Exceptions

Exception TypeCondition
XmlExceptionThe node is not an Element node, the System.Xml.XmlReader.LocalName property of the Element node does not equal localname, the System.Xml.XmlReader.NamespaceURI property of the Element node does not equal ns, or an error occurred while parsing the XML.

Description

[Behaviors: As described above. ]

[Default: This method calls the System.Xml.XmlReader.MoveToContent method. If the returned node is an Element node, this method compares the System.Xml.XmlReader.LocalName and System.Xml.XmlReader.NamespaceURI properties of the node to localname and ns, respectively. If they are equal, this method calls the System.Xml.XmlReader.Read method to read the element and move to the next node. ]

[Overrides: Override this method to customize the behavior of this method in types derived from the XmlReader class. ]

[Usage: Use this method to read an Element node with the specified local name and namespace URI, and advance the reader to the next node. ]

See Also

System.Xml.XmlReader Class, System.Xml Namespace

XmlReader.ReadString Method

public abstract string ReadString();

Summary

Reads the contents of an element or text node as a string.

Return Value

A String containing the contents of the Element or Text node, or System.String.Empty if the reader is positioned on any other type of node.

Exceptions

Exception TypeCondition
XmlExceptionAn error occurred while parsing the XML.

Description

[Behaviors: If positioned on an Element node, this method concatenates all Text , SignificantWhitespace , Whitespace , and CDATA node types, and returns the concatenated data as the element content. If none of these node types exist, System.String.Empty is returned. Concatenation stops when any markup is encountered, which can occur in a mixed content model or when an element end tag is read.

If positioned on an element Text node, this method performs the same concatenation from the Text node to the element end tag. If the reader is positioned on an attribute Text node, this method has the same functionality as if the reader were position on the element start tag.

]

[Overrides: This method must be overridden in order to provide the functionality described above, as there is no default implementation. ]

See Also

System.Xml.XmlReader Class, System.Xml Namespace

XmlReader.ResolveEntity Method

public abstract void ResolveEntity();

Summary

Resolves the entity reference for EntityReference nodes.

Exceptions

Exception TypeCondition
InvalidOperationExceptionThe reader is not positioned on a System.Xml.XmlNodeType.EntityReference node.

Description

[Behaviors: This method parses the entity reference into child nodes. When the parsing is finished a new System.Xml.XmlNodeType.EndEntity node is placed in the stream to close the EntityReference scope. To step into the entity after this method has been called, call the System.Xml.XmlReader.ReadAttributeValue method if the entity is part of an attribute value, or the System.Xml.XmlReader.Read method if the entity is part of element content.

If this method is not called, the parser moves to the next node past the entity (child nodes are bypassed).

]

[Overrides: This method must be overridden in order to provide the functionality as described in the Behaviors and Usage sections, as there is no default implementation.

This method is required to throw an exception for implementations that do not support schema or DTD information. In this case, the System.Xml.XmlReader.CanResolveEntity property is required to return false .

]

[Usage: Use this method to resolve the entity reference for EntityReference nodes. Before calling this method, determine whether the reader can resolve an entity by checking the System.Xml.XmlReader.CanResolveEntity property. ]

See Also

System.Xml.XmlReader Class, System.Xml Namespace

XmlReader.Skip Method

public virtual void Skip();

Summary

Skips over the current element and moves the position of the current instance to the next node in the stream.

Exceptions

Exception TypeCondition
XmlExceptionThe XML was not well-formed, or an error occurred while parsing the XML.

Description

[Behaviors: If the reader is positioned on a non-empty Element node (System.Xml.XmlReader.IsEmptyElement equals false ), the position of the reader is moved to the node following the corresponding EndElement node. The properties of the nodes that are skipped over are not exposed. If the reader is positioned on any other node type, the position of the reader is moved to the next node, in this case behaving like the System.Xml.XmlReader.Read method. ]

[Default: This method calls the System.Xml.XmlReader.MoveToElement method before skipping to the next node. ]

[Overrides: Override this method to customize the behavior of this method in types derived from the XmlReader class. ]

[Usage: Use this method to skip over the current node. ]

See Also

System.Xml.XmlReader Class, System.Xml Namespace

XmlReader.AttributeCount Property

public abstract int AttributeCount { get; }

Summary

Gets the number of attributes on the current node.

Property Value

A Int32 containing the number of attributes on the current node, or zero if the current node does not support attributes.

Description

[Note: This property is only relevant to the DocumentType , Element , and XmlDeclaration node types of the XmlNodeType enumeration. Other node types do not have attributes. ]

[Behaviors: As described above.

This property is read-only.

]

[Overrides: This property must be overridden in order to provide the functionality described above, as there is no default implementation. ]

See Also

System.Xml.XmlReader Class, System.Xml Namespace

XmlReader.BaseURI Property

public abstract string BaseURI { get; }

Summary

Gets the base Uniform Resource Identifier (URI) of the current node.

Property Value

The base URI of the current node.

Description

[Note: A networked XML document is comprised of chunks of data aggregated using various W3C standard inclusion mechanisms and therefore contains nodes that come from different places. DTD entities are an example of this, but this is not limited to DTDs. The base URI tells where these nodes come from. If there is no base URI for the nodes being returned (for example, they were parsed from an in-memory string), System.String.Empty is returned. ]

[Behaviors: As described above.

This property is read-only.

]

[Overrides: This property must be overridden in order to provide the functionality described above, as there is no default implementation. ]

See Also

System.Xml.XmlReader Class, System.Xml Namespace

XmlReader.CanResolveEntity Property

public virtual bool CanResolveEntity { get; }

Summary

Gets a value indicating whether this reader can parse and resolve entities.

Property Value

A Boolean equal to false .

Description

[Behaviors: This property returns true to indicate the reader can parse and resolve entities; otherwise, false .

This property is read-only.

]

[Default: This property always returns false . ]

[Overrides: Override this property to return true for implementations that support schema or DTD information.]

[Usage: Use this property to determine whether the reader can parse and resolve entities. ]

See Also

System.Xml.XmlReader Class, System.Xml Namespace

XmlReader.Depth Property

public abstract int Depth { get; }

Summary

Gets the depth of the current node in the XML document.

Property Value

A Int32 containing the depth of the current node in the XML document.

Description

[Behaviors: As described above.

This property is read-only.

]

[Overrides: This property must be overridden in order to provide the functionality described above, as there is no default implementation. ]

See Also

System.Xml.XmlReader Class, System.Xml Namespace

XmlReader.EOF Property

public abstract bool EOF { get; }

Summary

Gets a value indicating whether the System.Xml.XmlReader.ReadState is System.Xml.ReadState.EndOfFile, signifying the reader is positioned at the end of the stream.

Property Value

A Boolean where true indicates the reader is positioned at the end of the stream; otherwise, false .

Description

[Behaviors: As described above.

This property is read-only.

]

[Overrides: This property must be overridden in order to provide the functionality described above, as there is no default implementation. ]

See Also

System.Xml.XmlReader Class, System.Xml Namespace

XmlReader.HasAttributes Property

public virtual bool HasAttributes { get; }

Summary

Gets a value indicating whether the current node has any attributes.

Property Value

A Boolean where true indicates the current node has attributes; otherwise, false .

Description

[Behaviors: As described above.

This property is read-only.

]

[Default: This property returns true if the System.Xml.XmlReader.AttributeCount property of the current node is greater than zero. ]

[Overrides: Override this property to customize the behavior of this property in types derived from the XmlReader class. ]

[Usage: Use this property to determine whether the current node has any attributes. ]

See Also

System.Xml.XmlReader Class, System.Xml Namespace

XmlReader.HasValue Property

public abstract bool HasValue { get; }

Summary

Gets a value indicating whether the current node can have an associated text value.

Property Value

A Boolean where true indicates the node on which the reader is currently positioned can have an associated text value; otherwise, false .

Description

[Note: The following members of the XmlNodeType enumeration can have an associated value: Attribute , CDATA , Comment , DocumentType , ProcessingInstruction , SignificantWhitespace , Text , Whitespace , and XmlDeclaration . ]

[Behaviors: As described above.

This property is read-only.

]

[Overrides: This property must be overridden in order to provide the functionality described above, as there is no default implementation. ]

See Also

System.Xml.XmlReader Class, System.Xml Namespace

XmlReader.IsDefault Property

public abstract bool IsDefault { get; }

Summary

Gets a value indicating whether the current node is an attribute that was generated from the default value defined in the DTD or schema.

Property Value

A Boolean where true indicates the current node is an attribute whose value was generated from the default value defined in the DTD or schema; false indicates the attribute value was explicitly set.

Description

[Behaviors: As described above.

This property is read-only.

]

[Overrides: This property should return false for implementations that do not support schema or DTD information. ]

See Also

System.Xml.XmlReader Class, System.Xml Namespace

XmlReader.IsEmptyElement Property

public abstract bool IsEmptyElement { get; }

Summary

Gets a value indicating whether the current node is an empty element (for example, <MyElement />).

Property Value

A Boolean where true indicates the current node is an element (System.Xml.XmlReader.NodeType equals System.Xml.XmlNodeType.Element) that ends with "/>", otherwise, false .

Description

[Behaviors: A corresponding EndElement node is not generated for empty elements.

This property is read-only.

]

[Overrides: This property must be overridden in order to provide the functionality described above, as there is no default implementation. ]

See Also

System.Xml.XmlReader Class, System.Xml Namespace

XmlReader.Item(int) Property

public abstract string this[int i] { get; }

Summary

Retrieves the value of the attribute with the specified index relative to the containing element.

Parameters

i
A Int32 specifying the zero-based index of the attribute relative to the containing element.

Property Value

A String containing the value of the attribute.

Exceptions

Exception TypeCondition
ArgumentOutOfRangeExceptioni is less than 0 or greater than or equal to the System.Xml.XmlReader.AttributeCount of the containing element.

Description

[Behaviors: This property does not move the reader.]

[Overrides: This property must be overridden in order to provide the functionality described above, as there is no default implementation. ]

See Also

System.Xml.XmlReader Class, System.Xml Namespace

XmlReader.Item(System.String) Property

public abstract string this[string name] { get; }

Summary

Retrieves the value of the attribute with the specified qualified name.

Parameters

name
A String specifying the qualified name of the attribute.

Property Value

A String containing the value of the specified attribute, or null if the attribute is not found.

Description

[Behaviors: This property does not move the reader.

If the reader is positioned on a DocumentType node, this method can be used to get the PUBLIC and SYSTEM literals.

]

[Overrides: This property must be overridden in order to provide the functionality described above, as there is no default implementation. ]

See Also

System.Xml.XmlReader Class, System.Xml Namespace

XmlReader.Item(System.String, System.String) Property

public abstract string this[string name, string namespaceURI] { get; }

Summary

Retrieves the value of the attribute with the specified local name and namespace URI.

Parameters

name
A String specifying the local name of the attribute.
namespaceURI
A String specifying the namespace URI of the attribute.

Property Value

A String containing the value of the specified attribute, or null if the attribute is not found.

Description

[Behaviors: This property does not move the reader. ]

[Overrides: This property must be overridden in order to provide the functionality described above, as there is no default implementation. ]

See Also

System.Xml.XmlReader Class, System.Xml Namespace

XmlReader.LocalName Property

public abstract string LocalName { get; }

Summary

Gets the local name of the current node.

Property Value

A String containing the local name of the current node or, for node types that do not have a name (like Text , Comment , and so on), System.String.Empty.

Description

[Behaviors: As described above. ]

[Overrides: This property must be overridden in order to provide the functionality described above, as there is no default implementation. ]

See Also

System.Xml.XmlReader Class, System.Xml Namespace

XmlReader.Name Property

public abstract string Name { get; }

Summary

Gets the qualified name of the current node.

Property Value

A String containing the qualified name of the current node or, for node types that do not have a name (like Text , Comment , and so on), System.String.Empty.

Description

[Behaviors: The qualified name is equivalent to the System.Xml.XmlReader.LocalName prefixed with System.Xml.XmlReader.Prefix and the ':' character. For example, System.Xml.XmlReader.Name is "bk:book" for the element <bk:book>.

The name returned is dependent on the System.Xml.XmlReader.NodeType of the node. The following node types return the listed values. All other node types return an empty string.

Node TypeName
Attribute The name of the attribute.
DocumentType The document type name.
Element The tag name.
EntityReference The name of the entity referenced.
ProcessingInstruction The target of the processing instruction.
XmlDeclaration The literal string "xml".
This property is read-only.

]

[Overrides: This property must be overridden in order to provide the functionality described above, as there is no default implementation. ]

See Also

System.Xml.XmlReader Class, System.Xml Namespace

XmlReader.NameTable Property

public abstract XmlNameTable NameTable { get; }

Summary

Gets the name table used by the current instance to store and look up element and attribute names, prefixes, and namespaces.

Property Value

The XmlNameTable used by the current instance.

Description

[Behaviors: Element and attribute names, prefixes, and namespaces are stored as individual String objects when a document is read.

This property is read-only.

]

[Overrides: This property must be overridden in order to provide the functionality described above, as there is no default implementation. ]

See Also

System.Xml.XmlReader Class, System.Xml Namespace

XmlReader.NamespaceURI Property

public abstract string NamespaceURI { get; }

Summary

Gets the namespace URI associated with the node on which the reader is positioned.

Property Value

A String containing the namespace URI of the current node or, if no namespace URI is associated with the current node, System.String.Empty.

Description

[Behaviors: This property is relevant to Element and Attribute nodes only.

Namespaces conform to the W3C "Namespaces in XML" recommendation, REC-xml-names-19990114.

This property is read-only.

]

[Overrides: This property must be overridden in order to provide the functionality described above, as there is no default implementation. ]

See Also

System.Xml.XmlReader Class, System.Xml Namespace

XmlReader.NodeType Property

public abstract XmlNodeType NodeType { get; }

Summary

Gets the type of the current node.

Property Value

One of the members of the XmlNodeType enumeration representing the type of the current node.

Description

[Behaviors: This property does not return the following XmlNodeType members: Document , DocumentFragment , Entity , EndEntity , and Notation .

This property is read-only.

]

[Overrides: This property must be overridden in order to provide the functionality described above, as there is no default implementation. ]

See Also

System.Xml.XmlReader Class, System.Xml Namespace

XmlReader.Prefix Property

public abstract string Prefix { get; }

Summary

Gets the namespace prefix associated with the current node.

Property Value

A String containing the namespace prefix associated with the current node.

Description

[Note: A namespace prefix is used as a reference for a namespace URI and is defined in an element declaration. For example, <someElement xmlns:bk="someURL">, defines a prefix name "bk". ]

[Behaviors: As described above.

This property is read-only.

]

[Overrides: This property must be overridden in order to provide the functionality described above, as there is no default implementation. ]

See Also

System.Xml.XmlReader Class, System.Xml Namespace

XmlReader.QuoteChar Property

public abstract char QuoteChar { get; }

Summary

Gets the quotation mark character used to enclose the value of an attribute.

Property Value

A Char specifying the quotation mark character (" or ') used to enclose the value of an attribute.

Description

[Behaviors: As described above.

This property is read-only.

]

[Overrides: This property must be overridden in order to provide the functionality described above, as there is no default implementation. ]

See Also

System.Xml.XmlReader Class, System.Xml Namespace

XmlReader.ReadState Property

public abstract ReadState ReadState { get; }

Summary

Gets the read state of the reader.

Property Value

One of the members of the ReadState enumeration.

Description

[Behaviors: As described above.

This property is read-only.

]

[Overrides: This property must be overridden in order to provide the functionality described above, as there is no default implementation. ]

See Also

System.Xml.XmlReader Class, System.Xml Namespace

XmlReader.Value Property

public abstract string Value { get; }

Summary

Gets the text value of the current node.

Property Value

A String containing the text value of the current node.

Description

[Behaviors: The value returned depends on the System.Xml.XmlReader.NodeType. The following table lists node types that have a value to return. All other node types return System.String.Empty.

Node TypeValue
Attribute The value of the attribute.
CDATA The content of the CDATA section.
Comment The content of the comment.
DocumentType The internal subset.
ProcessingInstruction The entire content, excluding the target.
SignificantWhitespace The white space between markup in a mixed content model, or in the scope of xml:space = "preserve".
Text The content of the text node.

Whitespace The white space between markup.
XmlDeclaration The content of the declaration.
This property is read-only.

]

[Overrides: This property must be overridden in order to provide the functionality described above, as there is no default implementation. ]

See Also

System.Xml.XmlReader Class, System.Xml Namespace

XmlReader.XmlLang Property

public abstract string XmlLang { get; }

Summary

Gets the current xml:lang scope.

Property Value

A String containing the current xml:lang scope.

Description

[Behaviors: As described above.

This property is read-only.

]

[Overrides: This property must be overridden in order to provide the functionality described above, as there is no default implementation. ]

See Also

System.Xml.XmlReader Class, System.Xml Namespace

XmlReader.XmlSpace Property

public abstract XmlSpace XmlSpace { get; }

Summary

Gets the current xml:space scope.

Property Value

One of the members of the XmlSpace enumeration. If no xml:space scope exists, this property defaults to System.Xml.XmlSpace.None.

Description

[Behaviors: As described above.

This property is read-only.

]

[Overrides: This property must be overridden in order to provide the functionality described above, as there is no default implementation. ]

See Also

System.Xml.XmlReader Class, System.Xml Namespace