- Qt 6.11
- Qt Core
- C++ Classes
- QXmlStreamEntityResolver
- Qt 6.11.2 Reference Documentation

# QXmlStreamEntityResolver Class

The QXmlStreamEntityResolver class provides an entity resolver for a QXmlStreamReader. More...

Header: | `#include <QXmlStreamEntityResolver>`
CMake: | `find_package(Qt6 REQUIRED COMPONENTS Core)` `target_link_libraries(mytarget PRIVATE Qt6::Core)`
qmake: | `QT += core`

- List of all members, including inherited members
- QXmlStreamEntityResolver is part of XML Classes.

Note: All functions in this class are reentrant.

## Public Functions

virtual | ~QXmlStreamEntityResolver()
virtual QString | resolveUndeclaredEntity(const QString &name)

## Detailed Description

Use to inform QXmlStreamReader how to expand entities not declared in the internal-set of the DTD.

### Security Considerations

#### Entity Cycles

You must take care to avoid resolving entities in cycles, because QXmlStreamReader only detects and rejects cycles in entities defined in the DTD, not in entities expanded from an implementation of the QXmlStreamEntityResolver interface.

This is by design: QXmlStreamReader puts the work on the implementation of a concrete QXmlStreamEntityResolver. For static mappings, like XML Entity Definitions for Characters, this is trivially guaranteed, so running some tracking in the background would just slow things down for everyone.

Things get interesting when you read entity definitions from external input, including untrusted sources. In this case, your implementation must ensure the expansions it uses as input are cycle-free. This is a simple graph operation that can be implemented in linear time and space and can be performed up front at load time, so it doesn't affect resolveUndeclaredEntity() performance.

#### Entity Expansion Limit

At the moment, entities resolved by this class do not count against QXmlStreamReader::entityExpansionLimit(). This may change in future versions of Qt.

For the time being, you need to enforce some upper expansion limit yourself, if you read entity definitions from external input. After cycle detection, longest-path calculation is a simple graph operation that can be implemented in linear time and space and can be performed up front at load time, so it, too, doesn't affect resolveUndeclaredEntity() performance.

See also QXmlStreamReader::setEntityResolver().

## Member Function Documentation

### `[virtual noexcept]` QXmlStreamEntityResolver::~QXmlStreamEntityResolver()

Destroys the entity resolver.

### `[virtual]` QString QXmlStreamEntityResolver::resolveUndeclaredEntity(const QString &name)

Reimplement this function to resolve the undeclared entity name and return its replacement text. If the entity is unknown to the entity resolver, return a null string: `QString()`. This will raise an error in QXmlStreamreader. An empty, but non-null string is considered a valid expansion of the entity, and will not cause an error.

The default implementation always returns `QString()`.