Skip to content

[Serializer] XmlEncoder: Make load flags configurable #18036

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

Closed
wants to merge 6 commits into from
Closed
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
9 changes: 6 additions & 3 deletions src/Symfony/Component/Serializer/Encoder/XmlEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,18 @@ class XmlEncoder extends SerializerAwareEncoder implements EncoderInterface, Dec
private $format;
private $context;
private $rootNodeName = 'response';
private $loadOptions;

/**
* Construct new XmlEncoder and allow to change the root node element name.
*
* @param string $rootNodeName
* @param string $rootNodeName
* @param int|null $loadOptions A bit field of LIBXML_* constants
*/
public function __construct($rootNodeName = 'response')
public function __construct($rootNodeName = 'response', $loadOptions = null)
{
$this->rootNodeName = $rootNodeName;
$this->loadOptions = null !== $loadOptions ? $loadOptions : LIBXML_NONET | LIBXML_NOBLANKS;
}

/**
Expand Down Expand Up @@ -81,7 +84,7 @@ public function decode($data, $format, array $context = array())
libxml_clear_errors();

$dom = new \DOMDocument();
$dom->loadXML($data, LIBXML_NONET | LIBXML_NOBLANKS);
$dom->loadXML($data, $this->loadOptions);

libxml_use_internal_errors($internalErrors);
libxml_disable_entity_loader($disableEntities);
Expand Down