The capability of expanding general entity references when reading XML data and having the resulting expanded text returned depends on the type of XmlReader used to read the data. Character entity references are always expanded automatically.
The XmlValidatingReader and XmlTextReader classes have an EntityHandling property that specifies how entities should be handled. The EntityHandling property can be set to one of the EntityHandling enumeration values. The default on the XmlValidatingReader class is to expand entity references (the EntityHandling property is set to ExpandEntities by default). The XmlTextReader class does not expand general entities by default (the EntityHandling property is set to ExpandCharEntities by default). When the EntityHandling property is set to ExpandCharEntities, only character entity references are expanded and general entity references are returned as general nodes. In this case, entity references are expanded when the ResolveEntity method is called.
The XmlNodeReader class has a ResolveEntity method that must be called to expand the references. To determine the ability of certain XmlReader objects to resolve entities, see the CanResolveEntity property.
Note: |
|---|
In the
.NET Framework version 2.0, the recommended practice is to create XmlReader instances using the XmlReaderSettings class and the Create method. This allows you to take full advantage of all the new features introduced in the .NET Framework 2.0. For more information, see Creating XML Readers.
|
Concepts
Other Resources