Skip to content

Commit a6e8143

Browse files
committed
Auto-insert attribute namespace if it's not already known
1 parent c47e705 commit a6e8143

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/Attribute.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,14 @@ public static function fromXML(DOMAttr $attr): static
106106
*/
107107
public function toXML(DOMElement $parent): DOMElement
108108
{
109+
if ($this->getNamespaceURI() !== null && !$parent->lookupPrefix($this->getNamespacePrefix())) {
110+
$parent->setAttributeNS(
111+
'http://www.w3.org/2000/xmlns/',
112+
'xmlns:' . $this->getNamespacePrefix(),
113+
$this->getNamespaceURI(),
114+
);
115+
}
116+
109117
$parent->setAttributeNS(
110118
$this->getNamespaceURI(),
111119
!in_array($this->getNamespacePrefix(), ['', null])

0 commit comments

Comments
 (0)