Resolves the entity reference and returns the replacement string. For use with DtdProcessing.Parse.
The replacement string for the entity reference. If the entity is not a parsed general entity, null
is returned.
When the parser encounters an entity reference, it calls this method. This method can be used to programmatically resolve entity references. For example, you can use it to expand predefined entities such as < and >.
This method is called by the XmlReader when it encounters an entity reference.
If the entity reference is not a parsed general entity (e.g., a parameter entity or an external entity that cannot be resolved), this method should return null
.
Important: To prevent security vulnerabilities such as XML external entity (XXE) attacks, it is highly recommended to disable DTD processing or configure it securely. When DtdProcessing.Parse
is used, this method is invoked. Ensure you understand the implications and implement appropriate validation and sanitization if you are resolving entities.
The following C# code demonstrates how to use XmlReader.ResolveEntity
to process an XML document with entities:
When you run this code, the output will show the resolved text content:
.NET Framework: Supported in version 1.0 and later.
.NET Standard: Supported in version 1.0 and later.
.NET Core: Supported in version 2.0 and later.