The content of the current node as a uint
.
InvalidOperationException
: The current node is not a text node, attribute, or CDATA section.FormatException
: The content is not a valid 32-bit unsigned integer.XmlException
: Error processing the XML.This method reads the content of the current node and returns it as a 32-bit unsigned integer. If the node content cannot be represented as a uint
, a FormatException
is thrown. This method can be called on text nodes, attribute nodes, and CDATA section nodes. It will automatically advance to the next node if the current node is an element that contains only text.
using System;
using System.Xml;
public class Example
{
public static void Main(string[] args)
{
string xml = "<root><value>12345</value></root>";
XmlReader reader = XmlReader.Create(new System.IO.StringReader(xml));
while (reader.Read())
{
if (reader.IsStartElement())
{
if (reader.Name == "value")
{
reader.Read(); // Move to the text node
try
{
uint uintValue = reader.ReadContentAsUInt32();
Console.WriteLine($"The value is: {uintValue}");
}
catch (FormatException)
{
Console.WriteLine("The content is not a valid unsigned integer.");
}
catch (InvalidOperationException)
{
Console.WriteLine("Cannot read content as unsigned integer from this node type.");
}
}
}
}
reader.Close();
}
}