ReadUInt32()
Reads the current node's value as a 32-bit unsigned integer.
Return Value
System.UInt32
The 32-bit unsigned integer value of the current node.
Remarks
This method reads the value of the current node as a System.UInt32
. If the value cannot be parsed as a 32-bit unsigned integer, an System.FormatException
is thrown.
This method can only be called on nodes that contain a value that can be represented as a 32-bit unsigned integer, such as an attribute or an element with text content. If called on other node types, the behavior is undefined or may result in an exception.
Exceptions
System.FormatException
: The value of the current node is not a valid 32-bit unsigned integer.System.Xml.XmlException
: An error occurred while reading the XML.
Example
The following example demonstrates how to use the ReadUInt32()
method to read an attribute value.
using System;
using System.Xml;
public class Example
{
public static void Main(string[] args)
{
string xml = "<root><element attribute="4294967295"/></root>";
XmlDocument doc = new XmlDocument();
doc.LoadXml(xml);
XmlNodeReader reader = new XmlNodeReader(doc);
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Attribute && reader.Name == "attribute")
{
try
{
uint uintValue = reader.ReadUInt32();
Console.WriteLine($"Attribute value as UInt32: {uintValue}");
}
catch (FormatException ex)
{
Console.WriteLine($"Error parsing attribute value: {ex.Message}");
}
}
}
reader.Close();
}
}