Skip to content

Element AppendElement

Thomas Weinert edited this page Jul 12, 2018 · 5 revisions

FluentDOM\DOM\Element::appendElement()

FluentDOM\DOM\Element appendElement(
  string $name [ , string $content = '' [ , array $attributes = NULL ]]
)
FluentDOM\DOM\Element appendElement(
  string $name [ , array $attributes = NULL ]
)

A shortcut to create, configure an append an element node.

Usage

$document = new FluentDOM\DOM\Document();
$document->appendChild($document->createElement('div'));
$document->documentElement->appendElement(
  'span', 'Hello World!', ['class' => 'message']
);

echo $document->saveXML();

Output

<?xml version="1.0" encoding="UTF-8"?>
<div><span class="message">Hello World!</span></div>
Clone this wiki locally