Esempio n. 1
0
     assert_is_a($actual, FluidContext::class);
     $actual = $xml->appendChild('child', 'value', true);
     assert_is_a($actual, FluidContext::class);
     $actual = $xml->appendChild(['child1', 'child2'], true);
     assert_is_a($actual, FluidContext::class);
     $actual = $xml->appendChild(['child1' => 'value1', 'child2' => 'value2'], true);
     assert_is_a($actual, FluidContext::class);
     $actual = $xml->appendChild('child', ['attr' => 'value'], true);
     assert_is_a($actual, FluidContext::class);
     $actual = $xml->appendChild(['child1', 'child2'], ['attr' => 'value'], true);
     assert_is_a($actual, FluidContext::class);
 });
 it('should add namespaced children', function () {
     $xml = new FluidXml();
     $xml->namespace(new FluidNamespace('x', 'x.com'));
     $xml->namespace(fluidns('xx', 'xx.com', FluidNamespace::MODE_IMPLICIT));
     $xml->appendChild('x:xTag1', true)->appendChild('x:xTag2');
     $xml->appendChild('xx:xxTag1', true)->appendChild('xx:xxTag2')->appendChild('tag3');
     $expected = "<doc>\n" . "  <x:xTag1 xmlns:x=\"x.com\">\n" . "    <x:xTag2/>\n" . "  </x:xTag1>\n" . "  <xxTag1 xmlns=\"xx.com\">\n" . "    <xxTag2/>\n" . "    <tag3/>\n" . "  </xxTag1>\n" . "</doc>";
     assert_equal_xml($xml, $expected);
 });
 $doc = "<doc>\n" . "  <parent>content</parent>\n" . "</doc>";
 $dom = new \DOMDocument();
 $dom->loadXML($doc);
 it('should fill the document with an XML string', function () {
     $xml = new FluidXml(['root' => null]);
     $xml->appendChild('<root/>');
     $expected = "<root/>";
     assert_equal_xml($xml, $expected);
 });
 it('should fill the document with an XML string with multiple root nodes', function () {
Esempio n. 2
0
        echo "Chapter {$ii} has title '{$title}' with id '{$id}'.\n";
    }
}
/*
* To retrieve all DOMNode in one operation there is the ->asArray() method.
*/
$chapters_nodes = $chapters->array();
// Returns an array of DOMNode.
echo "————————————————————————————————————————————————————————————————————————————————\n";
/***************
 * Namespaces. *
 ***************/
/*
* To use a namespace you have to register its identifier together with its uri.
*/
$xhtml = fluidns('xhtml', 'http://www.w3.org/1999/xhtml');
$book->namespace($xhtml)->namespace('svg', 'http://www.w3.org/2000/svg')->namespace('xsl', 'http://www.w3.org/TR/xsl', FluidNamespace::MODE_IMPLICIT)->add('xhtml:h1')->add(['xsl:template' => ['xsl:variable']])->query('//xhtml:h1')->add('svg:shape');
echo $book->xml();
echo "————————————————————————————————————————————————————————————————————————————————\n";
/*******************
 * Removing Nodes. *
 *******************/
$food->remove('//egg');
// Removes all the eggs.
// Which is the same of
// $food->query('//egg')->remove();     // Removes all the eggs using a query.
// $food->query('/doc')->remove('egg'); // Removes all the eggs using a relative XPath.
/* ->remove(...$xpath)
 * accepts the same arguments of
 * ->query(...$xpath)
 * Remember that, like `->query()`, even `->remove()` accepts multiple XPath strings.