From 390c8c44ad6c83b943605686b53cfd87f8fbf0e9 Mon Sep 17 00:00:00 2001 From: Babichev Maxim Date: Thu, 11 Jan 2018 13:17:37 +0300 Subject: [PATCH] Update XMLReader.php --- src/XMLReader/XMLReader.php | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/src/XMLReader/XMLReader.php b/src/XMLReader/XMLReader.php index e474157..65ab2b8 100644 --- a/src/XMLReader/XMLReader.php +++ b/src/XMLReader/XMLReader.php @@ -231,10 +231,7 @@ public function asXML($storage, $name = 'bavix', array $attributes = []) { $element = $this->element($name); - foreach ($attributes as $attr => $value) { - $element->setAttribute($attr, $value); - } - + $this->addAttributes($element, $attributes); $this->addAttributes($element, $this->copyright); $this->document()->appendChild($element); $this->convert($element, $this->_convertStorage($storage)); @@ -295,9 +292,30 @@ protected function addNodeWithKey($key, DOMElement $element, $storage) { $this->addAttributes($element, $storage); } - else if ($key === '@value' && \is_string($storage)) + else if ($key === '@value') { - $element->nodeValue = \htmlspecialchars($storage); + if (\is_string($storage)) + { + $element->nodeValue = \htmlspecialchars($storage); + + return; + } + + $dom = new \DOMDocument(); + $dom->loadXML( + (new XMLReader())->asXML($storage) + ); + + $fragment = $element->ownerDocument->createDocumentFragment(); + + foreach ($dom->firstChild->childNodes as $value) + { + $fragment->appendXML( + $value->ownerDocument->saveXML($value) + ); + } + + $element->appendChild($fragment); } else {