Skip to content
Thomas Weinert edited this page Aug 13, 2014 · 3 revisions

FluentDOM\Nodes::load()

FluentDOM\Nodes load(mixed $source [, string $contentType = 'text/xml']);

Load the provided source into the Nodes instance. The method can handle other FluentDOM\Nodes, DOMDocument and DOMNode instances directly and has default loaders for XML, HTML and Json.

The loaders are replaceable using FluentDOM\Nodes::loaders(). The constructor calls load() if a $source is provided. The $contentType is used to decide which loader is used.

Usage: Loading Xml

$fd = new FluentDOM\Nodes();
$fd->load('<message>Hello World!</message>');

foreach ($fd->find('//message') as $message) {
  echo $message->nodeValue;
}

Output

Hello World!

Usage: Load JSON

$json = '{ "message" : "Hello World!" }';
$fd = new FluentDOM\Nodes($json, 'text/json');
foreach ($fd->find('//message') as $message) {
  echo $message->nodeValue;
}

Output

Hello World!
Clone this wiki locally