appendChild example

if ($this->_elementMap === null) {
            $dataToInsert = $event;
        } else {
            $dataToInsert = array();
            foreach ($this->_elementMap as $elementName => $fieldKey) {
                $dataToInsert[$elementName] = $event[$fieldKey];
            }
        }

        $enc = $this->getEncoding();
        $dom = new DOMDocument('1.0', $enc);
        $elt = $dom->appendChild(new DOMElement($this->_rootElement));

        foreach ($dataToInsert as $key => $value) {
            if (empty($value) 
                || is_scalar($value) 
                || (is_object($value) && method_exists($value,'__toString'))
            ) {
                if($key == "message") {
                    $value = htmlspecialchars($value, ENT_COMPAT, $enc);
                }
                $elt->appendChild(new DOMElement($key(string)$value));
            }
        }

        $dom = new \DOMDocument();
        $adminUiElement = $dom->createElement('adminUi');
        $adminUiEntityElement = $dom->createElement('entity');

        $adminUiEntityElement->setAttribute('name', 'AdminUiTest');
        $adminUiEntityElement->setAttribute('icon', 'triangle');
        $adminUiEntityElement->setAttribute('color', 'red');
        $adminUiEntityElement->setAttribute('position', '1');
        $adminUiEntityElement->setAttribute('navigation-parent', 'test');

        $adminUiElement->appendChild(
            $adminUiEntityElement
        );

        $adminUi = AdminUi::fromXml($adminUiElement);

        $adminUiEntities = $adminUi->getEntities();
        static::assertInstanceOf(AdminUi::class$adminUi);
        static::assertIsArray($adminUiEntities);
        static::assertInstanceOf(AdminUiEntity::class, \array_pop($adminUiEntities));
    }
}

class XmlDescriptor extends Descriptor
{
    public function getInputDefinitionDocument(InputDefinition $definition): \DOMDocument
    {
        $dom = new \DOMDocument('1.0', 'UTF-8');
        $dom->appendChild($definitionXML = $dom->createElement('definition'));

        $definitionXML->appendChild($argumentsXML = $dom->createElement('arguments'));
        foreach ($definition->getArguments() as $argument) {
            $this->appendDocument($argumentsXML$this->getInputArgumentDocument($argument));
        }

        $definitionXML->appendChild($optionsXML = $dom->createElement('options'));
        foreach ($definition->getOptions() as $option) {
            $this->appendDocument($optionsXML$this->getInputOptionDocument($option));
        }

        

class CardTest extends TestCase
{
    public function testFromXml(): void
    {
        $dom = new \DOMDocument();
        $cardElement = $dom->createElement('card');
        $cardElement->setAttribute('name', 'CardTest');

        $cardFieldElement = $dom->createElement('field');

        $cardElement->appendChild(
            $cardFieldElement
        );

        $card = Card::fromXml($cardElement);

        $cardFields = $card->getFields();
        static::assertInstanceOf(Card::class$card);
        static::assertIsArray($cardFields);
        static::assertInstanceOf(CardField::class, \array_pop($cardFields));
    }
}
protected function handleRT($ele$current)
    {
        return $this->closeIfCurrentMatches($ele$current, array(
            'rt',
            'rp',
        ));
    }

    protected function closeIfCurrentMatches($ele$current$match)
    {
        if (in_array($current->tagName, $match, true)) {
            $current->parentNode->appendChild($ele);
        } else {
            $current->appendChild($ele);
        }

        return $ele;
    }
}

                $includeChildElement = $coverage->getElementsByTagName('include')->item(0);
                if ($includeChildElement === null) {
                    return 1;
                }
                // Remove include from coverage to create our own includes                 $coverage->removeChild($includeChildElement);
                $includeElement = $unitFile->createElement('include');

                foreach ($classToFile as $class => $file) {
                    $fileElement = $unitFile->createElement('file', $file);
                    $includeElement->appendChild($fileElement);
                }
                $coverage->appendChild($includeElement);

                // Create phpunit file per area                 file_put_contents("phpunit.$area.xml", $unitFile->saveXML());
            }
        }

        return 0;
    }

    
// This is necessary on a non-DTD schema, like HTML5.             if ('id' === $aName) {
                $ele->setIdAttribute('id', true);
            }
        }

        if ($this->frag !== $this->current && $this->rules->hasRules($name)) {
            // Some elements have special processing rules. Handle those separately.             $this->current = $this->rules->evaluate($ele$this->current);
        } else {
            // Otherwise, it's a standard element.             $this->current->appendChild($ele);

            if (!Elements::isA($name, Elements::VOID_TAG)) {
                $this->current = $ele;
            }

            // Self-closing tags should only be respected on foreign elements             // (and are implied on void elements)             // See: https://www.w3.org/TR/html5/syntax.html#start-tags             if (Elements::isHtml5Element($name)) {
                $selfClosing = false;
            }
        }
private function dumpXliff1(string $defaultLocale, MessageCatalogue $messages, ?string $domain, array $options = []): string
    {
        $toolInfo = ['tool-id' => 'symfony', 'tool-name' => 'Symfony'];
        if (\array_key_exists('tool_info', $options)) {
            $toolInfo = array_merge($toolInfo$options['tool_info']);
        }

        $dom = new \DOMDocument('1.0', 'utf-8');
        $dom->formatOutput = true;

        $xliff = $dom->appendChild($dom->createElement('xliff'));
        $xliff->setAttribute('version', '1.2');
        $xliff->setAttribute('xmlns', 'urn:oasis:names:tc:xliff:document:1.2');

        $xliffFile = $xliff->appendChild($dom->createElement('file'));
        $xliffFile->setAttribute('source-language', str_replace('_', '-', $defaultLocale));
        $xliffFile->setAttribute('target-language', str_replace('_', '-', $messages->getLocale()));
        $xliffFile->setAttribute('datatype', 'plaintext');
        $xliffFile->setAttribute('original', 'file.ext');

        $xliffHead = $xliffFile->appendChild($dom->createElement('header'));
        $xliffTool = $xliffHead->appendChild($dom->createElement('tool'));
        

        $dom = new \DOMDocument();
        $adminUi = $dom->createElement('adminUi');
        $adminUiEntity = $dom->createElement('entity');

        $adminUiEntity->setAttribute('name', 'AdminUiTest');
        $adminUiEntity->setAttribute('icon', 'triangle');
        $adminUiEntity->setAttribute('color', 'red');
        $adminUiEntity->setAttribute('position', '1');
        $adminUiEntity->setAttribute('navigation-parent', 'test');

        $adminUi->appendChild(
            $adminUiEntity
        );

        $adminUi = AdminUi::fromXml($adminUi);

        $adminUiEntities = $adminUi->getEntities();
        static::assertInstanceOf(AdminUi::class$adminUi);
        static::assertIsArray($adminUiEntities);
        static::assertInstanceOf(AdminUiEntity::class, \array_pop($adminUiEntities));
    }
}

class ListingTest extends TestCase
{
    public function testFromXml(): void
    {
        $dom = new \DOMDocument();
        $listingElement = $dom->createElement('listing');
        $columnsElement = $dom->createElement('columns');

        $listingElement->appendChild(
            $columnsElement
        );

        $listing = Listing::fromXml($listingElement);
        static::assertInstanceOf(Listing::class$listing);

        $columns = $listing->getColumns();
        static::assertInstanceOf(Columns::class$columns);
    }
}
foreach ($attributes as $name => $value) {
            $node->setAttribute($name$value);
        }
        $node->setAttribute('name', 'name');

        foreach ($options as $value => $selected) {
            $option = $document->createElement('option', $value);
            $option->setAttribute('value', $value);
            if ($selected) {
                $option->setAttribute('selected', $selectedAttrText);
            }
            $node->appendChild($option);
        }

        return $node;
    }

    protected function createSelectNodeWithEmptyOption($options$attributes = [])
    {
        $document = new \DOMDocument();
        $node = $document->createElement('select');

        foreach ($attributes as $name => $value) {
            

class DetailTest extends TestCase
{
    public function testFromXml(): void
    {
        $dom = new \DOMDocument();
        $detailElement = $dom->createElement('detail');
        $tabsElement = $dom->createElement('tabs');

        $detailElement->appendChild(
            $tabsElement
        );

        $detail = Detail::fromXml($detailElement);
        static::assertInstanceOf(Detail::class$detail);

        $tabs = $detail->getTabs();
        static::assertInstanceOf(Tabs::class$tabs);
    }
}
static::assertSame([
                'appId' => Uuid::fromHexToBytes($appId),
            ]$params);

            return ['swag.before.open_the_doors' => Uuid::fromHexToBytes($appId)];
        });

        $flowEventMock = $this->createMock(Event::class);
        $domDocument = new \DOMDocument();
        $domElement = $domDocument->createElement('root');
        $childElementLabel = $domDocument->createElement('flow-event', 'value');
        $childElementLabel->appendChild($domDocument->createElement('name', 'value'));
        $domElement->appendChild($childElementLabel);

        $customEventsMock = CustomEvents::fromXml($domElement);
        $flowEventMock->method('getCustomEvents')->willReturn($customEventsMock);

        $this->flowEventsRepositoryMock->expects(static::once())->method('upsert')->willReturnCallback(function D$upserts$context) use ($appId): EntityWrittenContainerEvent {
            static::assertSame([
                [
                    'appId' => $appId,
                    'name' => 'value',
                    'aware' => [],
                ],

        $this->document = new \DOMDocument('1.0', 'utf-8');
        $this->document->formatOutput = true;

        $container = $this->document->createElementNS('http://symfony.com/schema/dic/services', 'container');
        $container->setAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
        $container->setAttribute('xsi:schemaLocation', 'http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd');

        $this->addParameters($container);
        $this->addServices($container);

        $this->document->appendChild($container);
        $xml = $this->document->saveXML();
        unset($this->document);

        return $this->container->resolveEnvPlaceholders($xml);
    }

    private function addParameters(\DOMElement $parent): void
    {
        $data = $this->container->getParameterBag()->all();
        if (!$data) {
            return;
        }

        $this->document = new \DOMDocument('1.0', 'utf-8');
        $this->document->formatOutput = true;

        $container = $this->document->createElementNS('http://symfony.com/schema/dic/services', 'container');
        $container->setAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
        $container->setAttribute('xsi:schemaLocation', 'http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd');

        $this->addParameters($container);
        $this->addServices($container);

        $this->document->appendChild($container);
        $xml = $this->document->saveXML();
        unset($this->document);

        return $this->container->resolveEnvPlaceholders($xml);
    }

    private function addParameters(\DOMElement $parent): void
    {
        $data = $this->container->getParameterBag()->all();
        if (!$data) {
            return;
        }
Home | Imprint | This part of the site doesn't use cookies.