Skip to content

Commit 8128ec4

Browse files
committed
Prevent Attribute::toXML from setting xmlns:xmlns attributes
1 parent 68e205e commit 8128ec4

1 file changed

Lines changed: 7 additions & 10 deletions

File tree

src/XML/Attribute.php

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -98,19 +98,16 @@ public static function fromXML(Dom\Attr $attr): static
9898
*/
9999
public function toXML(Dom\Element $parent): Dom\Element
100100
{
101-
if ($this->getNamespaceURI() !== null && !$parent->lookupPrefix($this->getNamespacePrefix())) {
102-
$parent->setAttributeNS(
103-
C::NS_XMLNS,
104-
'xmlns:' . $this->getNamespacePrefix(),
105-
$this->getNamespaceURI(),
106-
);
101+
$prefix = $this->getNamespacePrefix();
102+
$namespaceURI = $this->getNamespaceURI();
103+
104+
if ($namespaceURI !== null && !in_array($prefix, ['xml', 'xmlns']) && !$parent->lookupPrefix($prefix)) {
105+
$parent->setAttributeNS(C::NS_XMLNS, 'xmlns:' . $prefix, $namespaceURI);
107106
}
108107

109108
$parent->setAttributeNS(
110-
$this->getNamespaceURI(),
111-
!in_array($this->getNamespacePrefix(), ['', null])
112-
? ($this->getNamespacePrefix() . ':' . $this->getAttrName())
113-
: $this->getAttrName(),
109+
$namespaceURI,
110+
!in_array($prefix, ['', null]) ? ($prefix . ':' . $this->getAttrName()) : $this->getAttrName(),
114111
strval($this->getAttrValue()),
115112
);
116113

0 commit comments

Comments
 (0)