Skip to content

[Serializer] Add CDATA_WRAPPING_NAME_PATTERN support to XmlEncoder #21274

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 6, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions serializer/encoders.rst
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,10 @@ These are the options available on the :ref:`serializer context <serializer-cont
``cdata_wrapping_pattern`` (default: ``/[<>&]/``)
A regular expression pattern to determine if a value should be wrapped
in a CDATA section.
``cdata_wrapping_name_pattern`` (default: ``false``)
A regular expression pattern that defines the names of fields whose values
should always be wrapped in a CDATA section, even if their contents don't
require it. Example: ``'/(firstname|lastname)/'``
``ignore_empty_attributes`` (default: ``false``)
If set to true, ignores all attributes with empty values in the generated XML

Expand All @@ -216,6 +220,10 @@ These are the options available on the :ref:`serializer context <serializer-cont

The ``ignore_empty_attributes`` option was introduced in Symfony 7.3.

.. versionadded:: 7.4

The ``cdata_wrapping_name_pattern`` option was introduced in Symfony 7.4.

Example with a custom ``context``::

use Symfony\Component\Serializer\Encoder\XmlEncoder;
Expand Down