You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using XmlEncoder::decode on a node that does not have children and the node has a namespace defined then the namespace is not in the array even if it is needed for attributes on that node.
This results in an invalid xml when encoding it again to XML.
In the following example on how to reproduce there is a namespaced attribute xsi:noNamespaceSchemaLocation but after reading the xml and writing it again this is now invalid xml and throws a warning when trying to read it: PHP Warning: XMLReader::read(): test.xml:2: namespace error : Namespace prefix xsi for noNamespaceSchemaLocation on property is not defined
The method XmlEncoder::parseXmlAttributes could check if an attribute has a namespace and at least fetch this namespace from the $node like it is done in XmlEncoder::decode in case the root node has child nodes:
foreach ($xpath->query('namespace::*', $dom->documentElement) as $nsNode) {
$data['@'.$nsNode->nodeName] = $nsNode->nodeValue;
}
Additional Context
No response
The text was updated successfully, but these errors were encountered:
…tarld)
This PR was merged into the 5.4 branch.
Discussion
----------
[Serializer] Fix XML attributes not added on empty node
| Q | A
| ------------- | ---
| Branch? | 5.4
| Bug fix? | yes
| New feature? | no
| Deprecations? | no
| Issues | Fix#52385
| License | MIT
Add XML namespace attributes on node whether they have chlidren or not.
Commits
-------
4ee28fb [Serializer] Fix XML attributes not added on empty
Symfony version(s) affected
6.3
Description
When using
XmlEncoder::decode
on a node that does not have children and the node has a namespace defined then the namespace is not in the array even if it is needed for attributes on that node.This results in an invalid xml when encoding it again to XML.
In the following example on how to reproduce there is a namespaced attribute
xsi:noNamespaceSchemaLocation
but after reading the xml and writing it again this is now invalid xml and throws a warning when trying to read it:PHP Warning: XMLReader::read(): test.xml:2: namespace error : Namespace prefix xsi for noNamespaceSchemaLocation on property is not defined
How to reproduce
Possible Solution
The method
XmlEncoder::parseXmlAttributes
could check if an attribute has a namespace and at least fetch this namespace from the$node
like it is done inXmlEncoder::decode
in case the root node has child nodes:Additional Context
No response
The text was updated successfully, but these errors were encountered: