FluidXml\FluidXml::addChild PHP Méthode

addChild() public méthode

public addChild ( $child, $optionals )
    public function addChild($child, ...$optionals)
    {
        return $this->chooseContext(function ($cx) use($child, &$optionals) {
            return $cx->addChild($child, ...$optionals);
        });
    }

Usage Example

Exemple #1
0
// Exports the xml document as a string.
echo "————————————————————————————————————————————————————————————————————————————————\n";
/**********************
 * Context Switching. *
***********************/
/*
* Passing a 'true' boolean value to any method that performs an insertion of a node,
* returns the newly created node instead of the parent.
* This operation is called Context Switch.
* Methods that support this context switch are:
* - addChild($child, ...$optionals);
* - prependSibling($sibling, ...$optionals);
* - appendSibling($sibling, ...$optionals);
* and their alias methods (of course).
*/
$book->addChild('chapters', true)->addChild('chapter', 'Ideas About The Universe', ['id' => 123, 'first' => ''])->addChild('chapter', 'The Expanding Universe', ['id' => 321])->addChild('chapter', 'Black Holes', ['id' => 432])->addChild('chapter', 'Black Holes Ain\'t So Black', ['id' => 234]);
/********************
 * Appending Nodes. *
*********************/
/*
* Inserting a node can be performed in different ways,
* each one with its pros and cons.
*/
/*
* In this examples, it is used the concise syntax, but the same concepts
* are applicable to the standard syntax.
*/
$food = fluidxml('food');
$food->add('fruit')->add('fruit', 'orange');
// A 'fruit' node with 'orange' as content.
// A node can have even a bunch of attributes.
All Usage Examples Of FluidXml\FluidXml::addChild