CanResolveEntity Property

Gets a value indicating whether the XmlNodeReader can resolve entities.

NamespaceSystem.Xml
AssemblySystem.Xml.ReaderWriter
Assembly Version4.0.0.0
Platform.NET Framework, .NET Core, .NET 5+
Declarationpublic override bool CanResolveEntity { get; }

Syntax

public override bool CanResolveEntity { get; }

Remarks

When CanResolveEntity returns true, the reader can resolve entity references to their replacement text. This is particularly useful when processing XML documents that contain entity definitions.

The XmlNodeReader inherits this property from XmlReader. Its value depends on the underlying XmlNode and the way the reader was created.

Example

using System;
using System.Xml;

class Example
{
    static void Main()
    {
        string xml = @"<!DOCTYPE root [
            <!ENTITY myEntity ""Entity Content"">
        ]>
        <root>&myEntity;</root>";

        XmlDocument doc = new XmlDocument();
        doc.LoadXml(xml);

        using (XmlNodeReader reader = new XmlNodeReader(doc))
        {
            Console.WriteLine($""CanResolveEntity: {reader.CanResolveEntity}"");
            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.EntityReference)
                {
                    Console.WriteLine($""Entity: {reader.Name}"");
                }
            }
        }
    }
}

Output:

CanResolveEntity: True
Entity: myEntity

See Also