dox Executable Documentation

Manipulation

Renaming element

$this->given->theMarkUp('<some/><element></element>');
$this->when->nodes[0]->setName('other');
$this->when->nodes[1]->setName('stuff');
$this->then->itShouldBe('<other/><stuff></stuff>');

Set text content

$this->given->theMarkUp('Some Text');
$this->when->nodes[0]->setText('Other Content');
$this->then->itShouldBe('Other Content');

Deleting child

$this->given->theMarkUp('<father><child/><sister/><brother/></father>');
$child = $this->when->nodes[0]->getChildren()->get(1);
$this->when->nodes[0]->getChildren()->removeElement($child);
$this->then->itShouldBe('<father><child/><brother/></father>');

Deleting attribute

$this->given->theMarkUp('<one/><two some="stuff" other="value"/>');
$this->when->nodes[1]->getAttributes()->removeElement($this->when->nodes[1]->getAttribute('some'));
$this->then->itShouldBe('<one/><two other="value"/>');

Copying element

$this->given->theMarkUp('<dad><child prop=thing><other>Stuff</other></child></dad>');

* @var Element $copy

$dad = $this->when->nodes[0];
$copy = $dad->getChildren()->first()->copy();
$copy->setName('brother');
$copy->setAttribute('prop', 'thang');
$copy->getChildren()->first()->getChildren()->first()->setText('Other');
$dad->getChildren()->append($copy);
$this->then->itShouldBe('<dad><child prop=thing><other>Stuff</other></child><brother prop=thang><other>Other</other></brother></dad>');
$this->assertTrue($copy->getChildren()->first()->getParent() === $copy);